Status: Accepted
Owner: marianopeck
Labels: Type-Bug
New issue 5951 by marianopeck: Add #asBytesDescription to Number
http://code.google.com/p/pharo/issues/detail?id=5951This is something took from Magma and it is very nice to visualize unit of
measure to bytes. It gets the most approx. suffix and prints it that way.
Example: 1080000 asBytesDescription -> '1.08M'
10800 asBytesDescription -> '10.8k'
wanna include it in Pharo?
Number >> asBytesDescription
| suffixes |
suffixes := { 'k'"ilobytes". 'M'"egabytes". 'G'"igabytes".
'T'"erabytes". 'P'"etabytes". 'E'"xabytes". 'Z'"ettabytes".
'Y'"ottabytes"}.
suffixes size to: 1 by: -1 do:
[ : index | | units |
units := 1000 raisedTo: index.
self > units ifTrue: [ ^ ((self / units) asFloat roundTo:
0.01)
asString, (suffixes at: index) ] ].
^ self asString
_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker