I have noticed some questionable behaviour when converting byte sizes
into a human-readable form.
$ruby script\console Loading development environment (Rails 2.3.8) >> include ActionView::Helpers::NumberHelper => Object >> number_to_human_size(1000) => "1000 Bytes" # I wanted "1 kB" >> number_to_human_size(1000000) => "976.6 KB" # I wanted "1 MB" >>
- It’s using the wrong prefix for the multiplier, or using the wrong
multiplier for the prefix.
(a) If using SI / metric prefixes, the multiplier should be 1000
(b) If using a multiplier of 1024, the prefixes should be the binary
Mixing these up isn’t great but a lot of people do get it wrong, and
it’s a hard habit to break. Ideally I suppose the method could have
a :format option for the three types of behaviour:
:metric Use 1000 and metric prefixes
:binary Use 1024 and binary prefixes
:broken Use 1000 and binary prefixes
And default to :binary, perhaps.
- The “k” for “kilo” should be in lowercase.