s-yadav / react-number-format

React component to format numbers in an input or as a text.
MIT License
3.85k stars 404 forks source link

Rounding with decimalScale={1} #820

Open cwagner22 opened 8 months ago

cwagner22 commented 8 months ago

<NumericFormat value={51.97} decimalScale={1} /> renders 52.0 which is wrong in my opinion, it should be 52, without decimals.

https://codesandbox.io/p/sandbox/decimalscale-demo-forked-7zky75

Related to maximumFractionDigits mentioned in https://github.com/s-yadav/react-number-format/pull/752

s-yadav commented 6 months ago

Yes, that makes sense, as that would be closer to Intl.NumberFormat. But as it is a behaviour change, the best time to handle this will be with maximumFractionDigits, and minimumFractionDigits.

Meanwhile workaround is to handle it parent level by using Intl.NumberFormat.

<NumericFormat value={Intl.NumberFormat('en', {maximumFractionDigits: 1})} valueIsNumericString decimalScale={1} />