Click here to Skip to main content
15,881,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a input field of type number. And I want to retrieve the exact value entered by the user without losing the focus.
Means :
1. When user enter 1 it should return 1
2. When user enter 11 it should return 11
3. When user enter 11. it should return 11. means with decimal but it returns only 11

What I have tried:

I tried keyup event but the value for the element always came without decimal. And also tried the modelctrl.parsers.push but parsers do not fired when the input is decimal(dot).

I have checked the modelctrl.$viewValue, modelctrl.$modelValue. Everything is returning the value without decimal.
Posted
Updated 20-Feb-17 21:03pm
v2
Comments
Nathan Minier 21-Feb-17 7:42am    
Just to clarify, you want this to return an int if there is no decimal portion, and a float if there is?
leonidasvijay 21-Feb-17 23:28pm    
I have used a number type field. Actually I need to set a validation when the value contains a decimal value. When the value is 11.5 it is working fine.
Nathan Minier 22-Feb-17 7:08am    
You should likely look at the validation logic if it's struggling with a numeric type in JS, which is very forgiving on numeric types.

If the validation is on the server-side, cast to float or double. The key thing to remember with JS is: how it's displayed is not necessarily exactly how it's stored. Browsers tend to do a whole bunch of parsing, even in the dev tools.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900