Skip to content

Conversation

@pjakubik
Copy link

Fix also speeds up the float and int formatting so that after adding extra logic to fix edge cases, humanateBytes and humanateBigBytes are faster than they were before.

More details on #103 fix

Here is what the code did with the specific issue reported with humanizing 31450000

  1. Calculate that this should be 31.45 MB
  2. Multiply 31.45 by 10 and add 0.5 -> 315.0
  3. Floor of 315.0 then divide by 10 -> 31.5
  4. Tell Sprintf to format 31.5 with no decimals -> Sprintf rounds to 32
  5. Return "32 MB" instead of expected "31 MB"

Fix now rounds differently depending on if value being rounded is >= 10 or <10 so that after rounding, Sprintf won't round again.

- dustin#103 double rounding edge case returns wrong value
- dustin#127 outputting 1000 kB instead of 1.0 MB for some values
- unit tests updated and/or added for above fixes

Fix also speeds up the float and int formatting so that after adding extra logic to fix edge cases, humanateBytes and humanateBigBytes are faster than they were before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant