角如何使用上述&lt 2位小数始终显示号码;输入&GT; [英] Angular how to display number always with 2 decimal places in <input>
本文介绍了角如何使用上述&lt 2位小数始终显示号码;输入&GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有,我想总是有2位小数显示NG-model的浮点值的&LT;输入&GT;
:
&LT;输入NG模型=myNumb步=0.01类型=数字&GT;
这适用于当myNumb有小数最如此。但它不会迫使2位小数显示,如果myNumb有少于2位小数(3.2),或者是一个整数(30)结果
我怎样才能迫使2小数位中显示的&LT;输入&GT;
字段
解决方案
的 AngularJS - 用2位小数输入数字的它可以帮助...
过滤:
<醇开始=3>
设置常规的前pression验证采用NG-模式输入。在这里,我想用最大的2位小数,并用点分隔只接受数字。
块引用>&LT;输入类型=数字NAME =myDecimal占位符=十进制NG模型=myDecimalNG-模式=/ ^ [0-9] + ?(\\。[0-9] {1,2})$ /步=0.01/&GT;
I have a float value for the ng-model that I would like to always display with 2 decimal places in the
<input>
:<input ng-model="myNumb" step ="0.01" type="number">
This works for most case when "myNumb" has decimal. But it will not force display of the 2 decimal places if "myNumb" has less than 2 decimal places (3.2), or an integer(30)
How can I force a display of 2 decimal place in the<input>
field解决方案AngularJS - Input number with 2 decimal places it could help... Filtering:
- Set the regular expression to validate the input using ng-pattern. Here I want to accept only numbers with a maximum of 2 decimal places and with a dot separator.
<input type="number" name="myDecimal" placeholder="Decimal" ng-model="myDecimal" ng-pattern="/^[0-9]+(\.[0-9]{1,2})?$/" step="0.01" />
这篇关于角如何使用上述&lt 2位小数始终显示号码;输入&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文