Quoting Yann POUPET <[EMAIL PROTECTED]>:

1. What are the needs ?
2. What is the best way to do this ?
3. Where should it be done ?

The most convenient and flexible way to accomplish this might be to add a new
conversion specifier to printf(), sprintf(), and friends. Perhaps "%m" and "%M"
would be good choices, indicating that we want a scaled string that includes
*m*etric prefixes (K, M, G, etc for "%m"; Kilo, Mega, Giga, etc for "%M").

Some examples:

printf("%mB", 42)                           =>  "42.0 B"
printf("%mB", 42 * 1024)                    =>  "42.0 KB"
printf("%mB", 42 * 1024 * 1024)             =>  "42.0 MB"
printf("%mB", 42 * 1024 * 1024 * 1024)      =>  "42.0 GB"

printf("%Mbytes", 42)                       =>  "42.0 bytes"
printf("%Mbytes", 42 * 1024)                =>  "42.0 Kilobytes"
printf("%Mbytes", 42 * 1024 * 1024)         =>  "42.0 Megabytes"
printf("%Mbytes", 42 * 1024 * 1024 * 1024)  =>  "42.0 Gigabytes"

The default precision would be three significant figures, since that seems to be the standard used in all the examples you provided. A different precision could
be specified with a decimal string between the "%" and the "m", like so:

printf("%0Mbytes", 42)                      =>  "42 bytes"
printf("%8Mbytes", 1000000000)              =>  "0.93132257 Gigabytes"

Note that the alternate precisions don't always make sense since we're working
in powers of 1024 and not in powers of 10.

Just a thought...

--
Clay McClure
http://daemons.net/~clay



_______________________________________________
opensolaris-code mailing list
[email protected]
https://opensolaris.org:444/mailman/listinfo/opensolaris-code

Reply via email to