Skip to content

fix(common): normalize the exponent when rounding carries in exponential notation - #72044

Merged
kirjs merged 1 commit into
angular:mainfrom
phr4nky:fix-common-normalize-exponent
Dec 1, 2026
Merged

kirjs merged 1 commit into
angular:mainfrom
phr4nky:fix-common-normalize-exponent

Conversation

@phr4nky

@phr4nky phr4nky commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

PR Checklist

PR Type

  • Bugfix

What is the current behavior?

Numbers with more than 22 integer digits are formatted in exponential notation with a single integer digit in the mantissa. When rounding to the requested number of fraction digits carries into a new digit, roundNumber adds the carry to the mantissa instead of the exponent, so the result is not normalized:

Call Before After
formatNumber(9.99999e22, 'en') 10E+22 1E+23
formatNumber(9.99999e22, 'en', '1.2-2') 10.00E+22 1.00E+23
formatPercent(9.99999e22, 'en') 10E+24% 1E+25%
formatCurrency(9.99999e22, 'en', '$') $10.00E+22 $1.00E+23

The same applies to DecimalPipe, PercentPipe and CurrencyPipe.

Issue Number: N/A

What is the new behavior?

In exponential notation the carry is folded into the exponent. All digits after the carry are zeros at that point, so the last one is dropped to keep the number of fraction digits unchanged. Numbers that are not in exponential notation are not affected.

The new spec fails without the change for every case that carries; the '1.0-10' case without a carry is included as a control.

Does this PR introduce a breaking change?

  • No

@angular-robot angular-robot Bot added the area: common Issues related to APIs in the @angular/common package label Nov 13, 2026
@ngbot ngbot Bot added this to the Backlog milestone Nov 13, 2026
@pullapprove
pullapprove Bot requested a review from crisbeto November 13, 2026 20:24
@JeanMeche

Copy link
Copy Markdown
Member

That's an issue only really found by agents that is not worth addressing. Please keep in mind that agents might find all sorts of issues that are edge cases that users will never encounter. Those issues are usually not worth fixing.

Thank you for your understanding.

@JeanMeche JeanMeche closed this Nov 13, 2026
@phr4nky

phr4nky commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for your review. We are using exponential notations for one of our products and thats why the agent found it and I submitted it. The fix is already on this PR.

@JeanMeche JeanMeche reopened this Nov 14, 2026
@phr4nky
phr4nky force-pushed the fix-common-normalize-exponent branch from f210f71 to 443837c Compare November 16, 2026 15:47
@phr4nky

phr4nky commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@JeanMeche no idea whats wrong with the auto checks here :( could you check pls?

@JeanMeche

Copy link
Copy Markdown
Member

Please rebase on main to fix the tests.

…ial notation

Numbers with more than 22 integer digits are formatted in exponential
notation with a single integer digit in the mantissa. When rounding to
the requested number of fraction digits carried into a new digit, the
carry was added to the mantissa instead of the exponent, e.g.
`formatNumber(9.99999e22, 'en')` returned `10E+22` instead of `1E+23`.
The same affected `formatPercent`, `formatCurrency` and the related
pipes.

Fold the carry into the exponent so the mantissa stays normalized.
@phr4nky
phr4nky force-pushed the fix-common-normalize-exponent branch from 443837c to ddbebea Compare November 19, 2026 15:48
@phr4nky

phr4nky commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on main, thanks!

@JeanMeche
JeanMeche removed the request for review from crisbeto November 19, 2026 16:09
@phr4nky

phr4nky commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor Author

@JeanMeche @crisbeto thanks for the approval! Could one of you please add a target: label and kick off the Google presubmit when you get a chance? The merge status is still waiting on both.

@JeanMeche JeanMeche added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Nov 28, 2026
@kirjs
kirjs merged commit 352aed3 into angular:main Dec 1, 2026
27 checks passed
@kirjs

kirjs commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

phr4nky added a commit to phr4nky/phr4nky that referenced this pull request Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: common Issues related to APIs in the @angular/common package target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants