Mahesh Reddy

Mahesh Reddy

  • NA
  • 363
  • 17.4k

Decimal floating number should not exceed more than 2(2.11)

Jan 2 2019 12:13 AM
Hi,
In invoice i have 2 fields named as qty and price
i have stored these variables in one array
total number should not 2 decimals
Ex:123.12(I need like this)
123.123(I don't need) 
Could kindly any one help me 
Here my sample code
<tbody>
<tr ng-repeat="item in invoice.items">
<td><input type="number" ng-model="item.qty" class="form-control" /></td>
<td><input type="number" ng-model="item.price" class="form-control" /></td>
<td>{{item.qty * item.price}}</td>
</tr>
<tr>
<td><button type="button" class="btn btn-primary" ng-click="add()">Add item</button></td>
<td></td>
<td></td>
<td>Total : </td>
<td>{{total()}} €</td>
</tr>
</tbody>
Sum of ng repeat elements
..........................
$scope.total = function(){
var total = 0;
angular.forEach($scope.invoice.items, function(item){
total += item.qty * item.price;
})
return total;
}
});
 
 

Answers (5)