简体   繁体   English

数字十进制格式

[英]Number Decimal Format

I have a textbox and user enter a number in it. 我有一个文本框,用户在其中输入一个数字。 I want to allow 2 decimal digits. 我想允许2个十进制数字。

For example; 例如; number: 12,256 -> I want to allow 12,25 not 3 digits after comma(2 number after comma). 数字:12,256->我要允许12,25而不是逗号后的3位数字(逗号后为2个数字)。 How can I do it? 我该怎么做?

Thanks, John 谢谢,约翰

Use jQuery decimal mask plugin on your input field: 在输入字段上使用jQuery十进制掩码插件:

$("input").decimalMask({
  separator: ".",
  decSize: 2,
  intSize: 8
});

Here is a plugin description 这是一个插件说明

Yet one solution: jQuery: what is the best way to restrict “number”-only input for textboxes? 还有一个解决方案: jQuery:限制文本框仅“数字”输入的最佳方法是什么? (allow decimal points). (允许小数点)。 In this case try to set up your regular expression. 在这种情况下,请尝试设置您的正则表达式。

Hope if helpful.. 希望对您有帮助。

i would recommend using a user control that has two textboxes, one for the whole number part, one for the decimal part. 我建议使用一个具有两个文本框的用户控件,一个用于整数部分,一个用于小数部分。 it looks like an inelegant solution but if your software needs to work on clients with different regional settings, the standard thousand seperator and decimal seperator might cause a problem in the future. 它看起来像是一个不太好的解决方案,但是如果您的软件需要在具有不同区域设置的客户端上运行,则标准的千位分隔符和十进制分隔符将来可能会引起问题。 limiting the number of characters on the textbox with decimal part will solve your problem. 用小数部分限制文本框上的字符数将解决您的问题。

i would also recommend jquery for masked textbox formatting which is much more elegant than asp.net standard masked input controls. 我还建议使用jquery进行屏蔽的文本框格式,这比asp.net标准的屏蔽输入控件要优雅得多。

http://digitalbush.com/projects/masked-input-plugin/ http://digitalbush.com/projects/masked-input-plugin/

您可以从Ajax Control Toolkit使用MaskedEdit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM