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

How to get 'best-scaled' SI strings? #4

Closed
cobbr2 opened this issue Apr 22, 2010 · 2 comments
Closed

How to get 'best-scaled' SI strings? #4

cobbr2 opened this issue Apr 22, 2010 · 2 comments
Assignees

Comments

@cobbr2
Copy link

cobbr2 commented Apr 22, 2010

I'm looking for a method that scales the SI units to the most appropriate scaling prefix. E.g., if I have "4096 KiB", I see no direct method or trick that will format this to "4.0 MiB", though after perusing the source, I do see I can get there (if I already know the scale I want) by doing "4096 KiB".unit().to_s("MiB"), or ".0000032 cm".unit().to_s("nm").

But I'd like to do it without knowing the "best" scale; I often have to print values that might be 2 B, or 2 PiB, or anywhere in between. By best, I think I mean the fewest prefixes, where the prefix(es) chosen leave the scalar at a value between 1 and the next larger scaling prefix. I suspect the conversion needs to be able to say which scaling vector to use (e.g., the 2**(10x) vector vs. the 10**(3x) vector); wouldn't want to get in a fight between a RAM vendor and a disk vendor about what GB means.

I don't see anything in the referenced IEEE Xplore article about handling this part of the problem; I can see it might be a tad challenging when dealing with something like 4.2e-6 centigram nanoparsecs / kilosecond .

@olbrich
Copy link
Owner

olbrich commented Apr 22, 2010

This is an interesting problem which is easy to solve for some specific cases and trickier to solve in the general case. I'll think about it some more and see if I can't come up with a reasonable implementation. Test cases would be really handy.

@ghost ghost assigned olbrich Jul 19, 2013
@olbrich
Copy link
Owner

olbrich commented Jul 19, 2013

fixed in pull request #77

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

No branches or pull requests

2 participants