Perhaps that could be solved by feeding the function a constant object or mapping. Something like:
int2size(2048, Foo.BYTES_SIZE_BIN) => "2 KiB" int2size(2048, Foo.BYTES_SIZE_BIN_OLD) => "2 kb" int2size(2000, Foo.BITS_RATE_DEC) => "2 kbps" int2size(17, ([ "unit": " pellefanter", "foo_per_unit": 16, "precision": 17 )] ) => "1.0625 pellefanter"
That way I would at least use the int2size function as a base when building my own.
/ Peter Bortas
Previous text:
2002-12-05 22:38: Subject: Re: CHANGES line of the day
In the last episode (Dec 05), Niels Mller () @ Pike (-) developers forum said:
After writing some code similar to int2size, I'll suggest that it either skips the unit, and/or takes an additional argument that is the unit. E.g.
int2size(4200, "bps") ==> 4.1 Kbps
Perhaps one should have one function that produces 2^10 prefixes, and another one that produces standard SI (or whatever the stanrd is) prefixes. The latter function could take floats rather than ints, though. Like
foo(0.01, "s") => 10 ms
Or perhaps that gets a little too complicated, e.g. one would also want to provide the precision. Perhaps something for sprintf.
I think you've found the reason everyone writes their own. By the time you come up with a function that satisfies everyone, it'll have 6 arguments and no-one will bother to use it because it's too complicated :)
-- Dan Nelson dnelson@allantgroup.com
/ Brevbäraren