Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

number_to_human_size fails for some values

#1763

For some values, the helper method "number_to_human_size" gives a wrong result. See this examples:

Correct:

number_to_human_size(41500, :precision => 0)
=> "41 KB"

Wrong:

number_to_human_size(41100, :precision => 0)
=> "4 KB"

My Environment: * ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-darwin9.1.0] * Rails 2.2.2

Reported by Georg Ledermann · January 15th, 2009 @ 06:03 PM

State: resolved
Milestone: 2.3.6
Assigned to: Pratik Pratik
Importance: High

Activity

  1. Georg Ledermann
    Georg Ledermann
    • Tag changed from 2.2.2, helper, numberhelper, number_to_human_size to 2.2.2, helper, numberhelper, number_to_human_size, patch

    Here it's little patch to fix the bug (with tests added). It's a kind of a hack, perhaps someone can find a better way to fix this.

    January 15th, 2009 @ 10:22 PM

  2. Travis Briggs
    Travis Briggs

    I fixed this with a different approach, fixing the regex itself. The previous regex was misleading, because since the #{escaped_separator} was inside a zero or one group (ie ()?), it would match trailing zeros after any digit.

    I think this is a bit simpler fix, without special casing.

    March 19th, 2009 @ 02:01 AM

  3. Repository
    Repository
    • State changed from new to resolved

    May 17th, 2009 @ 06:23 PM

  4. Bira
    Bira

    This also affects 2-3-stable (and thus 2.3.4). Would it be possible to apply this patch to that branch as well?

    September 29th, 2009 @ 08:40 PM

  5. Michael Koziarski
    Michael Koziarski
    • Milestone changed from 2.x to 2.3.6
    • State changed from resolved to open
    • Assigned user set to Pratik

    September 29th, 2009 @ 09:21 PM

  6. Repository
    Repository
    • State changed from open to resolved

    October 17th, 2009 @ 01:38 AM