This is a migrated thread and some comments may be shown as answers.

[Solved] Restrict number of decimal places to 2 during input

1 Answer 24 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sam
Top achievements
Rank 1
Sam asked on 08 Dec 2011, 11:03 AM
For CurrencyBox, is there any way to restrict the number of decimal places a user can enter during input?

For e.g. I have a Unit Price field that I only want to store up to 2 decimal places in the database.
When using CurrencyBox, it allowed my users to enter any number of decimal places then round the value to 2 decimal places.
What I want is to just prevent the user to enter more than 2 decimal places. 

Is this possible with CurrencyBox?

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 09 Dec 2011, 03:20 PM
Hello Bt,

 
The Numeric/Currency/Percentage/IntegerTextBox does not restrict the user input while they types. Nevertheless, as you mentioned, once the user blur the input the component will round the number.
One possible solution is to wire the keydown event of the input element end prevent the input if the typed number has more than 2 decimal digits. Other option is to set the maxlength of the input element.

Regards,
Georgi Krustev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
NumericTextBox
Asked by
Sam
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or