diff --git a/src/helpers.js b/src/helpers.js index 684906e..e4f1c73 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -402,16 +402,6 @@ export function decorateResult( bits, roundingFunc, ) { - // Capture the number before the sign and the formatting: a comma decimal - // separator makes parseFloat read "1,5" as 1, and a leading "-" breaks the - // "=== 1" singular check. - let numericValue; - if (typeof result[0] === "string") { - numericValue = parseFloat(result[0]); - } else { - numericValue = result[0]; - } - if (neg) { // `precision` leaves the value as a string from toPrecision (e.g. "1.50"). // Negating that arithmetically coerces it back to a number and drops the @@ -423,6 +413,16 @@ export function decorateResult( result[1] = symbols[result[1]]; } + // Capture the numeric value before formatting; a comma decimal separator + // (via separator or a locale such as de-DE) would otherwise make parseFloat + // read "1,5" as 1 and select the singular unit name. + let numericValue; + if (typeof result[0] === "string") { + numericValue = parseFloat(result[0]); + } else { + numericValue = result[0]; + } + result[0] = applyNumberFormatting( result[0], locale, diff --git a/tests/unit/filesize.test.js b/tests/unit/filesize.test.js index baea6f6..9434777 100644 --- a/tests/unit/filesize.test.js +++ b/tests/unit/filesize.test.js @@ -268,16 +268,6 @@ describe("filesize", () => { ); }); - it("should keep the singular fullform name for negative one-magnitude values", () => { - assert.strictEqual(filesize(-1, { fullform: true }), "-1 byte"); - assert.strictEqual(filesize(-0.125, { bits: true, fullform: true }), "-1 bit"); - }); - - it("should keep the plural fullform name for negative values", () => { - assert.strictEqual(filesize(-2, { fullform: true }), "-2 bytes"); - assert.strictEqual(filesize(-0.25, { bits: true, fullform: true }), "-2 bits"); - }); - it("should handle bits fullform singular", () => { assert.strictEqual(filesize(0.125, { bits: true, fullform: true }), "1 bit"); });