imaskjs
imaskjs copied to clipboard
Can't get right number working with integers mask and providing values using decimal notation
Hi,
When fixing the mask number to work only with integers (scale: 0
), and the input has a value like: "1.00"
being provided to, in the input is shown 100
instead of 1
.
<IMaskInput
value="1.00"
mask={Number}
scale={0}
/>
you can see it running here: https://codesandbox.io/s/winter-river-tqepn
In the case I'm working on, I can't covert the number to integer and then back to string to get "1" instead of "1.00". That also feels really unnatural to me and feels like I'm missing something. Any ideas here? Thanks.
@icaroponce How about if you make the scale=2
? I forked your sandbox and made this small change, it seems fine to me:
https://codesandbox.io/s/inspiring-burnell-2ooz5
@umairhm The idea of scale=0
is really not to allow decimal numbers to this input.
I see the same problem in Angular... I use lodash round function as a workaround https://lodash.com/docs/4.17.15#round
Any news about the problem?
I solved converting the value to int when I receive from the API, as mentioned by icaroponce, but it doen'l look good to me. but I still have a problem when the user copies the value (15.000) from a spreadsheet and the value are transformed to 15000.
I noticed the same behavior when update mask scale property. I have an input with value 50.00. (Scale property is 2) When I update scale = 0, it will return 5000 in input instead of 50