Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#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 Russell Keith-Magee, 12 years ago

Resolution: wontfix
Status: newclosed

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.

comment:2 by Claude Paroz, 12 years ago

Component: Template systemDocumentation
Resolution: wontfix
Status: closedreopened
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

I can buy the rationale of #8733, but this should be documented.

comment:3 by Claude Paroz, 12 years ago

Owner: changed from nobody to Claude Paroz
Status: reopenednew

comment:4 by Claude Paroz, 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 Tim Graham <timograham@…>, 12 years ago

Resolution: fixed
Status: newclosed

In 63e6cd1bb3edccb4db1eb6a79153fa31d2114cd4:

Fixed #19348 - Clarified the units of filesizeformat.

Thanks george_edison for the report and Claude Paroz for the patch.

comment:6 by Tim Graham <timograham@…>, 12 years ago

In c90156fc188200795a24c24b9ea97eef32356e55:

[1.5.X] Fixed #19348 - Clarified the units of filesizeformat.

Thanks george_edison for the report and Claude Paroz for the patch.

Backport of 63e6cd1bb3 from master

Note: See TracTickets for help on using tickets.
Back to Top