Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,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;

@augmentcode augmentcode Bot Jul 9, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numericValue is captured before applyNumberFormatting, but applyNumberFormatting can round via localeOptions (e.g., maximumFractionDigits) or the pad/round path. That can produce outputs like "1 …bytes" while numericValue is still slightly above/below 1, leading to a pluralization mismatch with the rendered value.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

if (typeof result[0] === "string") {
numericValue = parseFloat(result[0]);
} else {
numericValue = result[0];
}

result[0] = applyNumberFormatting(
result[0],
locale,
Expand All @@ -427,15 +437,9 @@ export function decorateResult(
} else {
unit = BYTE;
}
let val;
if (typeof result[0] === "string") {
val = parseFloat(result[0]);
} else {
val = result[0];
}
// Determine singular/plural suffix
let suffix;
if (val === 1) {
if (numericValue === 1) {
suffix = EMPTY;
} else {
suffix = S;
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/filesize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ describe("filesize", () => {
);
assert.strictEqual(filesize(1234567890, { precision: 2, fullform: true }), "1.2 gigabytes");
});

it("should keep the plural fullform when a comma decimal separator is used", () => {
assert.strictEqual(filesize(1500000, { fullform: true, separator: "," }), "1,5 megabytes");
assert.strictEqual(filesize(1500000, { fullform: true, locale: "de-DE" }), "1,5 megabytes");
});
});

describe("Base and exponent options", () => {
Expand Down
Loading