我现在正在开展一个项目,其中我需要获取模态表中某个列的总和。是的,它会计算金额,但不包括小数点。 (例如,我希望结果将是194,000.26,但结果只显示193,000.00)所以它只是意味着它没有添加小数点。谁可以帮我解决我的代码?
以下是我的观点:
<tr data-ng-repeat="model in models | orderBy: sorting:reverse | filter : filter ">
<td>{{jsonDatetotext(model.RequestDate) | date:'MM/dd/yyyy'}}</td>
<td>
<a href="#" data-toggle="modal" data-target="#basicModalContent" data-ng-click="getSelectedPR(model)">
{{model.RequestID}}
</a>
</td>
<td>{{model.Number }}</td>
<td>{{model.ProgramName }}</td>
<td>{{model.FullName }}</td>
<td>{{model.PONo}}</td>
<td>{{StatusList[model.StatusID] | uppercase}}</td>
<td class="totalAmount"><span class="pull-right">{{model.TotalAmount | number:2}}</span>
</td>
<td>{{model.asadsf | lowercase}}</td>
</tr>
</table>
</div>
<!-- /.Modal Na ni -->
<div class="modal fade" id="basicModalContent" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body" id="exportablePRItems">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>PR #
</th>
<th>Item Description
</th>
<th>Supplier
</th>
<th>Account
</th>
<th>Currency
</th>
<th>Amount
</th>
<th>(USD) Amount
</th>
</tr>
</thead>
<tbody data-ng-repeat="selectedPR in selectedModal.ItemList">
<tr>
<td>{{selectedPR.RequestID}}</td>
<td>{{selectedPR.PartDesc}}</td>
<td>{{selectedPR.SupplierID }}</td>
<td>{{selectedPR.AccountType}}</td>
<td>{{selectedPR.CurrName }}</td>
<td data-ng-model="amount" class="amount">{{selectedPR.Amount | number:2}}</td>
<td>{{selectedPR.AmountUSD}}</td>
</tr>
</tbody>
<tr>
<td colspan="7"><b>Total Amount : </b>{{selectedModal.ItemList | sumbykey : 'Amount' | number:2}} </td>
</tr>
</table>
</div>
</div>
这是我的角度过滤器
PRApp.filter('sumbykey', function () {
return function (data, key) {
if (typeof (data) === 'undefined' || typeof (key) === 'undefined') {
return 0;
}
var sum = 0.00;
for (var i = data.length - 1; i >= 0; i--) {
sum += parseInt(data[i][key]);
}
return sum;
};
});
答案 0 :(得分:1)
也许可以尝试在过滤器中将parseInt
更改为parseFloat
?