我在我的应用程序中使用MEAN堆栈,将AngularJS作为我的前端。如何total sum
以及decimal value
,实际上我得到total sum value
但decimal value
不是calculated
... My Plunker 示例: - fob值totalsum我得到700,期望像700.57,然后转换率值总和我得到124,期望像124.10,如果有人知道解决方案帮助我们感谢....
我的控制器: -
.filter('sumOfValue', function () {
return function (data, key) {
debugger;
if (angular.isUndefined(data) && angular.isUndefined(key))
return 0;
var sum = 0;
angular.forEach(data,function(v,k){
sum = sum + parseInt(v[key]);
});
return sum;
}
})
我的Html: -
<td>{{resultValue | sumOfValue:'invoice_value_fob'}}</td>
<td>{{resultValue | sumOfValue:'conversion_rate'}}</td>
我的数据:
$scope.sryarndebitnote = [
{
"_id": "57ac1b6d82e1c5940ac3c730",
"user": {
"_id": "57400c32bd07906c1308e2cf",
"displayName": "mani selvam"
},
"__v": 0,
"created": "2016-08-11T06:30:05.118Z",
"shipment_id": "57ac19b982e1c5940ac3c72f",
"conversion_rate": "62.04",
"invoice_value_fob_currency": "Rs",
"invoice_value_fob": "300.231",
"invoice_quantity_unit": "KG",
"invoice_quantity": "37",
"invoice_date": "2016-08-17",
"supplier_name": "Msd",
"buyer_name": "Mani selvam .R"
},
{
"_id": "57b5af69df0475401f644b2e",
"user": {
"_id": "57400c32bd07906c1308e2cf",
"displayName": "mani selvam"
},
"__v": 0,
"created": "2016-08-18T12:51:53.671Z",
"shipment_id": "57b5af5bdf0475401f644b2d",
"conversion_rate": "62.06",
"exclusive": true,
"invoice_value_fob": "400.343",
"invoice_quantity": "97",
"supplier_name": "Msd",
"buyer_name": "Mani selvam .R"
},]
然后我需要decimal value
two digit
中的700.57
,700.574
,{{1}},请帮助我们感谢....
我创建了Plunker作为参考: - Plunker
答案 0 :(得分:1)
我认为这应该可以解决你的问题
<input type="number" name="myDecimal" placeholder="Decimal" ng-model="myDecimal" *step="0.01"* />
看见你的掠夺者。您可以将sumOfValue过滤器更改为以下内容: -
app.filter('sumOfValue', function () {
return function (data, key) {
debugger;
if (angular.isUndefined(data) && angular.isUndefined(key))
return 0;
var sum = 0;
angular.forEach(data,function(v,k){
sum = sum + parseFloat(v[key]);
});
return sum.toFixed(2);
}
添加工作plunker链接here