数据库调用返回此json格式的数据:
[{"expense_project_id":1,"project_id":1,"project_name":"miki project 1","item_amount":"0.7607479E5","item_count":7},{"expense_project_id":1,"project_id":2,"project_name":"project 2","item_amount":"0.7607479E5","item_count":7}]
我想格式化项目数量,以便它出来,例如,`21.87我试过这个:
parseFloat(this["this_amount"]).toFixed(2)
并且,在HTML页面中,我得到NaN
我该如何解决它?谢谢。
`
答案 0 :(得分:0)
要格式化“项目金额”,请在代码中将"this_amount"
更改为"item_amount"
:
parseFloat(this["item_amount"]).toFixed(2)
答案 1 :(得分:0)
你的变量是一个数组,所以你应该这样做:
var arr = [{"expense_project_id":1,"project_id":1,"project_name":"miki project 1","item_amount":"0.7607479E5","item_count":7},{"expense_project_id":1,"project_id":2,"project_name":"project 2","item_amount":"0.7607479E5","item_count":7}];
console.log(parseFloat(arr[0]["item_amount"]).toFixed(2))
答案 2 :(得分:0)
使用此item_amount
在您的结果中找不到this_amount
var arr = [{"expense_project_id":1,"project_id":1,"project_name":"miki project 1","item_amount":"0.7607479E5","item_count":7},{"expense_project_id":1,"project_id":2,"project_name":"project 2","item_amount":"0.7607479E5","item_count":7}];
console.log(parseFloat(arr[0]["item_amount"]).toFixed(2));