#19348 closed Cleanup/optimization (fixed)
Sizes returned by filesizeformat are incorrect.
Reported by: | Nathan Osman | Owned by: | Claude Paroz |
---|---|---|---|
Component: | Documentation | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
The template filter 'filesizeformat' appears to be returning incorrect results:
>>> from django.template.defaultfilters import filesizeformat >>> filesizeformat(123456789) u'117.7 MB'
According to the International System of Units (SI), the prefix "mega-" indicates a quantity of exactly 1000000. Django appears to be using 1024*1024 (1048576) to represent a megabyte which corresponds with the SI prefix "mebi-".
This error can be corrected in one of two ways:
- Replace the units in the strings returned with their proper equivalents:
KB => KiB MB => MiB etc.
- Use the correct values for KB, MB, etc.:
1024 => 1000 1048576 => 1000000 etc.
Change History (6)
comment:1 by , 12 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 by , 12 years ago
Component: | Template system → Documentation |
---|---|
Resolution: | wontfix |
Status: | closed → reopened |
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
I can buy the rationale of #8733, but this should be documented.
comment:3 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
comment:4 by , 12 years ago
Here's the text I suggest to add to the filesizeformat filter documentation. This should be revised/adapted by a native English speaker.
.. admonition:: File sizes and SI units Strictly speaking, ``filesizeformat`` does not conform to the International System of Units, which recommends to use KiB, MiB, GiB,... when byte sizes are calculated in powers of 1024 (which is the case here). Instead, Django has chosen to keep using traditional unit names (KB, MB, GB,...) corresponding to the more widespread usage.
comment:5 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Duplicate of #8733, and I haven't seen any significant change in the way the world views the SI prefixes since that ticket was closed wontfix.