Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number rounds up erroneously #33

Open
naknode opened this issue Aug 30, 2022 · 4 comments
Open

Number rounds up erroneously #33

naknode opened this issue Aug 30, 2022 · 4 comments
Assignees

Comments

@naknode
Copy link

naknode commented Aug 30, 2022

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?

@izolate
Copy link
Owner

izolate commented Sep 11, 2022

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 izolate self-assigned this Sep 11, 2022
@Sebastp
Copy link

Sebastp commented Apr 30, 2024

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

@Sebastp
Copy link

Sebastp commented Apr 30, 2024

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

@izolate
Copy link
Owner

izolate commented Apr 30, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants