hoist-react
hoist-react copied to clipboard
Issues with `fmtPercent` + `zeroPad` due to JS FP trailing precision
The numeric ZeroPad does not work in some cases, due to javascript number weirdness.
Example:
fmtPercent(10.1, { precision: 4, zeroPad: 2 } )
Expected result: 10.10%
Actual result: 10.1000%
Most values seem to work (ie, 10.2) but others do not (ie, 10.3).
The reason for this is the fact that fmtPercent multiplies by 100, and 0.101 * 100 -> 10.100000000000001
Therefore, the FormatNumber.countDecimalPlaces()
function counts all of those 0s as required precision, and the zeroPad is ignored.