Skip to content

fix: keep plural fullform name with a comma decimal separator#312

Merged
avoidwork merged 1 commit into
avoidwork:masterfrom
spokodev:fix/fullform-plural-comma-separator
Jul 9, 2026
Merged

fix: keep plural fullform name with a comma decimal separator#312
avoidwork merged 1 commit into
avoidwork:masterfrom
spokodev:fix/fullform-plural-comma-separator

Conversation

@spokodev

@spokodev spokodev commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Bug

fullform picks the singular unit name for values it should pluralize whenever a comma is the decimal separator.

filesize(1500000, { fullform: true })                  // "1.5 megabytes"  (correct)
filesize(1500000, { fullform: true, separator: "," })  // "1,5 megabyte"   (wrong)
filesize(1500000, { fullform: true, locale: "de-DE" }) // "1,5 megabyte"   (wrong)

Any value in [1, 2) is affected, and those are extremely common ("1,2 GB", "1,5 MB").

Cause

decorateResult decides the singular/plural suffix by running parseFloat over the value after it has already been formatted into a string. parseFloat("1,5") stops at the comma and returns 1, so the val === 1 check treats 1.5 as exactly one and drops the plural s. 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.

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.
@augmentcode

augmentcode Bot commented Jul 9, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: Fixes incorrect singular fullform unit names when decimal commas are used via separator: "," or locale formatting.

Changes:

  • Determines singular/plural based on the numeric value before locale/separator rendering
  • Adds regression tests covering comma separators and de-DE locale output

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/helpers.js
// 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.

@avoidwork avoidwork merged commit 93d3a82 into avoidwork:master Jul 9, 2026
2 checks passed
@avoidwork avoidwork mentioned this pull request Jul 9, 2026
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.

2 participants