millify icon indicating copy to clipboard operation
millify copied to clipboard

Number rounds up erroneously

Open djasnowski opened this issue 2 years ago • 4 comments

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?

djasnowski avatar Aug 30 '22 04:08 djasnowski

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.

izolate avatar Sep 11 '22 23:09 izolate

2 years later and it's still not fixed @izolate

Sebastp avatar Apr 30 '24 15:04 Sebastp

@izolate will you fix it or should I look for another way to do it?(not being passive aggressive)

Sebastp avatar Apr 30 '24 15:04 Sebastp

@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.

izolate avatar Apr 30 '24 16:04 izolate