Now I am working on a project in which I will need to get the sum of a specific column in a modal table. Yes, it calculates the sum, but the decimal point is not included. (for example, I expect the result to be 194,000.26, but the result will only show 193,000.00), so that just means that he did not add the decimal point. Anyone who can help me with my codes?
Here is my view:
<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> <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>
and here is my angular filter
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; }; });
source share