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

New option for precision #57

Closed
binarykitchen opened this issue Feb 23, 2020 · 5 comments · Fixed by #62
Closed

New option for precision #57

binarykitchen opened this issue Feb 23, 2020 · 5 comments · Fixed by #62

Comments

@binarykitchen
Copy link

Would be good to have an option to allow one digit after the floating-point.

Especially for scientific based apps.

@sindresorhus
Copy link
Owner

Can you provide an example of input, the output you currently get, and the output you'd like to get?

@binarykitchen
Copy link
Author

binarykitchen commented Feb 24, 2020

What I currently get:

prettyBytes(183715);
//=> '184 kB'

What I'm after:

prettyBytes(183715, { digits: 1 }); // new option
//=> '183.7 kB'

@sindresorhus
Copy link
Owner

prettyBytes(1337) results in 1.34 kB, so with the current behavior, I'm honestly not sure how it decides when to round or not...

How about a option, that by default, does the human readable thing and rounds when it makes sense? Like the current behavior was intended to do. And if you turn it off, you get the behavior you want with fraction digits. Like: https://developer.apple.com/documentation/foundation/bytecountformatter/1417887-isadaptive

@binarykitchen
Copy link
Author

I hear you. Probably sounds right.

The thing is, we are porting old code to a newer system (migrations) and have to ensure behaviour stays the same. And there is always one fraction digit in our bytes, can't question this. Hence, as long as I can force that with a new option, then I'm happy with it.

@sindresorhus
Copy link
Owner

How I'm imagining it, turning off the isAdaptive option would result in all units having one fractional digit.

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

Successfully merging a pull request may close this issue.

2 participants