imaskjs icon indicating copy to clipboard operation
imaskjs copied to clipboard

Can't get right number working with integers mask and providing values using decimal notation

Open icaroponce opened this issue 3 years ago • 4 comments

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 avatar Aug 04 '20 13:08 icaroponce

@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 avatar Aug 13 '20 14:08 umairhm

@umairhm The idea of scale=0 is really not to allow decimal numbers to this input.

icaroponce avatar Aug 15 '20 15:08 icaroponce

I see the same problem in Angular... I use lodash round function as a workaround https://lodash.com/docs/4.17.15#round

ivarorn85 avatar Oct 12 '20 13:10 ivarorn85

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.

FabricioCoutinho avatar Nov 18 '20 19:11 FabricioCoutinho

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

webpct avatar Feb 14 '23 20:02 webpct