RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.37k stars 2.17k forks source link

Numeric Mask is casting value to a number not supported by JavaScript #2715

Open dakota-kallas opened 1 year ago

dakota-kallas commented 1 year ago

Bug Description

I am trying to set the value of an input masked using the numeric extension of decimal type. If I manually type out "99,999,999,999,999,999,999,999.00" into the input, it works just fine and is masked correctly. However, if i try and set the value of the input using input.val("99,999,999,999,999,999,999,999.00") OR input.inputmask("setvalue", "99,999,999,999,999,999,999,999.00"), specifying that I am trying to set it as a string and not a number, it comes back as 123.00 in the input field. JavaScript only supports up to 2^53 as its largest number, so it is being casted to scientific notation of 1e+23 somewhere in the plugin, hence the output being 123.00. Even if I specify that I am trying to set the value of the input to a string, the plugin is still casting it to a number at some point, most likely with a parseFloat() call. This is completely breaking my input and makes it unusable as this input must be able to support numbers larger than 2^53.

Screenshots

image image image Also as a note, the min and max value also eventually get casted to numbers that are in scientific notation by the plugin using parseFloat() at some point.

CodePen Link

https://codepen.io/dakota-kallas/pen/poQgxaX?editors=1010

After some initial digging, it seems like this is caused by the following line in the inputmask.numeric.extensions.js file: initialValue = (opts.roundingFN(parseFloat(initialValue) * digitsFactor) / digitsFactor).toFixed(digits);

If I comment this line out, the value is set correctly. However, that is not a good solution as that would remove the roundingFN functionality.

System Information

721806280 commented 6 months ago

@RobinHerbots I have encountered the same problem, is it expected how long to solve this problem