im doing some math operations using angular js . while calculating percentage/vat price showing - 0.35000000000000003 like this . i need 0.35.
0.35000000000000003. how to trim decimals after 2 digits in .
<table align="center">
<h2>Tax Calculations</h2>
<tr>
<td>
quantity :
</td>
<td>
<asp:TextBox runat="server" ng-model="qty"/>
</td>
</tr>
<tr>
<td>
unit Price :
</td>
<td>
<asp:TextBox runat="server" ng-model="price"/>
</td>
</tr>
<tr>
<td>
total Amount :
</td>
<td>
<asp:TextBox runat="server" Text='{{qty * price}}' ReadOnly="true"/>
</td>
</tr>
<tr>
<td>
Vat Price at 5% :
</td>
<td>
<asp:TextBox runat="server" Text='{{(qty * price )/100 * 5}}' ReadOnly="true"/>
</td>
</tr>
<tr>
<td>
Total With Tax :
</td>
<td>
<asp:TextBox runat="server" Text='{{((qty * price )/100 * 5) + (qty*price)}}' ReadOnly="true"/>
</td>
</tr>
</table>
im doing some math operations using angular js . while calculating percentage/vat price showing - 0.35000000000000003 like this . i need 0.35.
0.35000000000000003. how to trim decimals after 2 digits in .
<table align="center">
<h2>Tax Calculations</h2>
<tr>
<td>
quantity :
</td>
<td>
<asp:TextBox runat="server" ng-model="qty"/>
</td>
</tr>
<tr>
<td>
unit Price :
</td>
<td>
<asp:TextBox runat="server" ng-model="price"/>
</td>
</tr>
<tr>
<td>
total Amount :
</td>
<td>
<asp:TextBox runat="server" Text='{{qty * price}}' ReadOnly="true"/>
</td>
</tr>
<tr>
<td>
Vat Price at 5% :
</td>
<td>
<asp:TextBox runat="server" Text='{{(qty * price )/100 * 5}}' ReadOnly="true"/>
</td>
</tr>
<tr>
<td>
Total With Tax :
</td>
<td>
<asp:TextBox runat="server" Text='{{((qty * price )/100 * 5) + (qty*price)}}' ReadOnly="true"/>
</td>
</tr>
</table>
Share
Improve this question
asked Mar 8, 2016 at 8:11
Krishna MohanKrishna Mohan
3151 gold badge7 silver badges15 bronze badges
4 Answers
Reset to default 4Please see the angularjs example
https://docs.angularjs/api/ng/filter/number
By the way ,suggest not mix asp and angularjs code into the same tag
//number with two digit
Negative number: <span>{{-val | number:2}}</span>
You can try javascript toFixed method like below
{{((qty * price )/100 * 5).toFixed(2)}}
you can try
<asp:TextBox runat="server" Text='{{(qty * price )/100 * 5 | number:2}}' ReadOnly="true"/>
angularjs document contains a very simple and pretty example. You can do this by :
<script>
angular.module('numberFilterExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.val = 1234.56789;
}]);
</script>
<div ng-controller="ExampleController">
<label>Enter number: <input ng-model='val'></label><br>
Default formatting: <span id='number-default'>{{val | number}}</span><br>
No fractions: <span>{{val | number:0}}</span><br>
Negative number: <span>{{-val | number:4}}</span>
</div>