[英]automatic currency on textbox in asp.net
what i want to happen is to have 12,345.00 rather than 12,345. 我想发生的是拥有12,345.00而不是12,345。
here is my code: 这是我的代码:
<asp:TextBox ID="txtProductPrice" runat="server" onkeyup = "javascript:this.value=Comma(this.value);" class="form-control" MaxLength ="6"></asp:TextBox>
and the javascript: 和javascript:
<script type="text/javascript" language="javascript">
function Comma(Num) {
Num += '';
Num = Num.replace(',', ''); Num = Num.replace(',', ''); Num = Num.replace(',', '');
Num = Num.replace(',', ''); Num = Num.replace(',', ''); Num = Num.replace(',', '');
x = Num.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1))
x1 = x1.replace(rgx, '$1' + ',' + '$2');
return x1 + x2;
}
</script>
any tricks? 有什么花招吗? thank you
谢谢
there is a jquery plugin called "jquery.formatCurrency" ( https://code.google.com/archive/p/jquery-formatcurrency/ ). 有一个名为“ jquery.formatCurrency”( https://code.google.com/archive/p/jquery-formatcurrency/ )的jquery插件。 It could meet your requirements.
它可以满足您的要求。
Sebastian 塞巴斯蒂安
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.