Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A negative value that rounds to zero is passed to
applyNumberFormattingas the string"-0"(so the sign survives). That string skipped the normal zero formatting:pad+separator, the rounding step turned"-0"into the number-0, and(-0).toString()is"0", so the sign was lost:filesize(-1, { exponent: 2, pad: true, separator: "," })gave"0,00 MB";locale,"-0"stayed a string, andString.prototype.toLocaleStringignores the locale and options, so padding,localeOptionsand the locale's minus sign were dropped:filesize(-1, { exponent: 2, pad: true, locale: "de" })gave"-0 MB"whilefilesize(1, …)gives"0,00 MB".Now
"-0"is parsed to-0in the locale branch (Intl prints negative zero with the locale's own sign, e.g."−0"forsv, same as other negatives), and the separator rounding step is skipped for it (rounding zero changes nothing). Non-locale output without a separator is unchanged ("-0.00 B"). Zero strings fromprecision(e.g."0.00") keep their current handling.Type of Change
Related Issues
Fixes #422
Testing
New test "should format a negative value that rounds to zero like any other zero" in
tests/unit/filesize.test.js(pad + separator, pad +de,localeOptions,sv, system locale). It fails on master ('0,00 MB'vs'-0,00 MB') and passes with the change.npm test: 285 pass, lint + format clean, 100% coverage.npm run buildsucceeds (dist not committed).Checklist
npm testpassesnpm run buildsucceeds