You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 .
The text was updated successfully, but these errors were encountered:
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.
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 .
The text was updated successfully, but these errors were encountered: