Repository navigation
fix(common): normalize the exponent when rounding carries in exponential notation - #72044
Conversation
|
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. |
|
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. |
f210f71 to
443837c
Compare
|
@JeanMeche no idea whats wrong with the auto checks here :( could you check pls? |
|
Please rebase on |
…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.
443837c to
ddbebea
Compare
|
Rebased on main, thanks! |
|
@JeanMeche @crisbeto thanks for the approval! Could one of you please add a |
PR Checklist
PR Type
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,
roundNumberadds the carry to the mantissa instead of the exponent, so the result is not normalized:formatNumber(9.99999e22, 'en')10E+221E+23formatNumber(9.99999e22, 'en', '1.2-2')10.00E+221.00E+23formatPercent(9.99999e22, 'en')10E+24%1E+25%formatCurrency(9.99999e22, 'en', '$')$10.00E+22$1.00E+23The same applies to
DecimalPipe,PercentPipeandCurrencyPipe.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?