[英]how to restrict decimal upto 2 digits only in angularjs
im doing some math operations using angular js . 我正在使用角度js做一些数学运算。 while calculating percentage/vat price showing - 0.35000000000000003 like this .
而计算百分比/增值税价格显示 - 0.35000000000000003这样。 i need 0.35.
我需要0.35。
0.35000000000000003. 0.35000000000000003。 how to trim decimals after 2 digits in .
如何在2位数之后修剪小数。
<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>
Please see the angularjs example 请参阅angularjs示例
https://docs.angularjs.org/api/ng/filter/number https://docs.angularjs.org/api/ng/filter/number
By the way ,suggest not mix asp.net and angularjs code into the same tag 顺便说一下,建议不要将asp.net和angularjs代码混合到同一个标签中
//number with two digit
Negative number: <span>{{-val | number:2}}</span>
您可以尝试javascript toFixed方法,如下所示
{{((qty * price )/100 * 5).toFixed(2)}}
你可以试试
<asp:TextBox runat="server" Text='{{(qty * price )/100 * 5 | number:2}}' ReadOnly="true"/>
angularjs document contains a very simple and pretty example. angularjs文档包含一个非常简单而漂亮的例子。 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.