简体   繁体   中英

Number Decimal Format

I have a textbox and user enter a number in it. I want to allow 2 decimal digits.

For example; number: 12,256 -> I want to allow 12,25 not 3 digits after comma(2 number after comma). How can I do it?

Thanks, John

Use jQuery decimal mask plugin on your input field:

$("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? (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.

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

您可以从Ajax Control Toolkit使用MaskedEdit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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