hoist-react
hoist-react copied to clipboard
Update `fmtNumber.zeroPad` arg to accept a number for "zero pad this many places out"
From Slack:
We have a use case where we want to format numbers (interest rates) out to a high precision (6-8), but only want to zeroPad them out to something like 2dps. E.g. we need to sometimes to print super-precise values like 1.12345678% but we also often have low-precision values, like 2. For those values, we want to print 2.00% and not 2.00000000%. Can’t justify on any scientific grounds :slightly_smiling_face: but to me if feels like two decimal places (in this context) provides some kind of “reasonable indication” that we’re being mindful of precision, without the silly looking string of eight zeroes.
One way to provide this functionality is to upgrade the current zeroPad
arg to take either a boolean (as it does now) or an int. The new form would specify the maximum number of decimal places out to which a formatted number should be zero-padded. A value of true
would effectively mean zeroPad = precision
.