Numbers and formatting
Jimmie Houchin
jhouchin at cableone.net
Tue Jun 21 17:11:14 UTC 2005
Hello,
I writing a little personal app which has parsed a directory tree and
gathered the sizes of all the files (mp3s). I want to present it to
myself in a nice format.
I don't want to see that my mp3 size is 61,599,788 bytes, but rather
58.7MB. I didn't find a method of conversion for such. I may have missed
such.
So the only way I've really found to get the 58.7mb is kind of ugly.
Below is my code.
-------------------------------
niceByteSizesFromBytes: numberBytes
| mb |
mb := (numberBytes asFloat)/(1024*1024).
mb := (((mb asScaledDecimal: 2) asString) allButLast: 2),'mb'.
^ mb
-------------------------------
It works, it gives me what I want.
But is there a better way. I've scoured the Integer, Float protocols for
appropriate methods. But alas I didn't see what I wanted. I am not a
math or cs guy so I could have easily missed something. I don't know
what floor and ceiling... are so... :)
Any words of wisdom greatly appreciated.
Jimmie
More information about the Squeak-dev
mailing list
|