fix: keep plural fullform name with a comma decimal separator#312
Merged
avoidwork merged 1 commit intoJul 9, 2026
Merged
Conversation
decorateResult decided the singular/plural fullform suffix by running
parseFloat over the already-formatted value string. When a comma decimal
separator is in play (via the separator option or a locale such as
de-DE), parseFloat("1,5") returns 1, so any value between 1 and 2 was
labelled singular, e.g. filesize(1500000, {fullform: true, separator:
","}) produced "1,5 megabyte" instead of "1,5 megabytes".
Capture the numeric value before it is formatted into a string and use
that for the plural decision.
🤖 Augment PR SummarySummary: Fixes incorrect singular fullform unit names when decimal commas are used via Changes:
🤖 Was this summary useful? React with 👍 or 👎 |
| // 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; |
There was a problem hiding this comment.
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
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
Merged
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.
Bug
fullformpicks the singular unit name for values it should pluralize whenever a comma is the decimal separator.Any value in
[1, 2)is affected, and those are extremely common ("1,2 GB", "1,5 MB").Cause
decorateResultdecides the singular/plural suffix by runningparseFloatover the value after it has already been formatted into a string.parseFloat("1,5")stops at the comma and returns1, so theval === 1check treats 1.5 as exactly one and drops the plurals. Pluralization must depend on the magnitude, not on how the number is rendered.Fix
Capture the numeric value before locale/separator formatting turns it into a string, and use that value for the plural decision. The precision string path (
"1.2", period) still parses correctly, so existing behavior is unchanged.Adds a regression test.