Hi all.

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"
    >>

1. 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
style (ki,Mi,Gi,...)
http://en.wikipedia.org/wiki/Binary_prefix

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.

2. The "k" for "kilo" should be in lowercase.
http://en.wikipedia.org/wiki/SI_prefix

TX

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to