Try to use standard SI prefixes for number_to_human_size, instead of the ancient 1024-based ones which were being used. Modern operating systems already do this, which results in a jarring mismatch between Rails' reported size and Mac OS'.
This particular version of the change may be controversial, but I believe in trying the simplest solution to the problem first, and this is the only solution which doesn't involve messing around with the options hash. :)
Try to use standard SI prefixes for number_to_human_size, instead of …
…the ancient 1024-based ones which were being used.
A kilobyte is 1024 bytes, the reason that some vendors refer to a kilobyte by 1000 bytes is beyond my understanding (simplicity?)
There's no need for us not to be precise and refer to it at 1024 bytes. What would be a far better alternative is to create an option to the hash which would allow it to use both bases of 1000 and 1024, with 1024 being the default, so this doesn't break someone's application with the change.
"Some vendors" call a kilobyte 1000 bytes because that is the standard. A "kibibyte" is 1024 bytes. Please don't fall under the same misconception as others.
More information: http://en.wikipedia.org/wiki/Binary_prefixes
This change won't "break someone's application" - it will fix their application.
"Some vendors": every known processor maker.
Yep. Also every hard disk manufacturer. But also Mac OS. And also Ubuntu.
Without this change, I upload a 1 MB file to my Rails app and it tells me it received 977 KB. As a user, I now wonder if it uploaded correctly. (Plus, even if kilobytes were correct for 1024, the abbreviation for kilo- is 'k', not 'K'. My patch fixed that too.)
I tried to do similar thing, some time ago:
Unfortunately there is no feedback from rails core team.
Until computers no longer use binary, -1 a million times. In every OS, 1MB = 1024KB = 1048576B.
Everyone uses the base 2 values except for hard drive manufacturers and OS X's Finder (but not the kernel).
If it says KB it is clear what it means, kB would be base 10 and kb would be a different unit of measure altogether.
I find it amusing that engineers will tell you the 2% error involved in mixing them up doesn't usually matter, while people building web apps think it does. :)
Also while Ubuntu and Mac OS may mysteriously count bits by si rather than binary powers, isn't Windows still the dominant consumer OS?
Since when did being dominant automatically mean being right?
And since when is "K" ever a valid prefix for these units?
I see several programs use binary prefixes nowadays, so they use base 2, but they refer to them as kibibytes (KiB) or mebibytes (MiB), etc. in stead. So 1 kB is 1000 bytes, but 1 KiB is 1024 bytes. People started to adopt this as early as 1998 (as per the Wikipedia article), but adoption has been slow. I think we should do one by default with an option to choose which one to use, maybe :prefix => :binary and :prefix => :si?
:prefix => :binary
:prefix => :si
If you are pragmatic having 1KB = 1000 does not makes sense at this moment when 90% of users still understand 1KB as 1024 bytes. Ext filesystem does use base 2 as an unit, it just converts before showing it to the user. Let's change the helper, after microsoft changes the way it displays file size numbers.
Ext2 shouldn't be displaying anything to the user. It's a filesystem. If you mean ls, then there are multiple options to that tool:
$ ls -l 1MB
-rw-r--r-- 1 trejkaz trejkaz 1000000 2011-04-26 12:33 1MB
$ ls -lh 1MB
-rw-r--r-- 1 trejkaz trejkaz 977K 2011-04-26 12:33 1MB
$ ls -l --si 1MB
-rw-r--r-- 1 trejkaz trejkaz 1.0M 2011-04-26 12:33 1MB
As for user understanding, if no applications were to show it the right way, users would never discover the right way. It's obviously up to applications to educate people on this, or everyone would keep doing it wrong (at least if we used eduardordm's logic. Proper units have been in place on both Mac OS and Ubuntu for some time, and I don't remember any major backlash about that.)
That aside, there are really three options here:
:prefix => :microsoft