millify
millify copied to clipboard
Number rounds up erroneously
https://codesandbox.io/s/magical-water-f7f84n?file=/src/index.js:0-164
import millify from "millify";
const OneBelow1Mill = 999999;
const OneBelow100G = 99999;
console.log(millify(OneBelow1Mill));
console.log(millify(OneBelow100G));
Output:
1M 100K
It should be:
999K 99K
Should it not? Why is it rounding up?
This is a consequence of how Number.prototype.toFixed
works. The starting number 99999
gets reduced to 99.999
, which is round to 100
with toFixed
. This does bring up a good point that the rounding logic can be improved, so thanks. Leave it with me and I'll see what I can do.
2 years later and it's still not fixed @izolate
@izolate will you fix it or should I look for another way to do it?(not being passive aggressive)
@Sebastp Truthfully, I forgot about this issue. Given that the solution isn't entirely clear at this stage, it may take longer to fix than you'd like (assuming you need a fix asap). If you want to take a crack at improving it and open a PR, I'd be happy to review. Otherwise, I'd recommend either waiting or looking for a workaround for the time being.