Skip to content

Round Amount values directly instead of through an Intl formatter - #164

Open
jessealama wants to merge 1 commit into
mainfrom
round-mathematical-values
Open

jessealama wants to merge 1 commit into
mainfrom
round-mathematical-values

Conversation

@jessealama

Copy link
Copy Markdown
Collaborator

This PR splits out a chunk of #161 by changing how the Amount constructor and .convertTo round when precision options are given. Instead of building a formatter object, calling FormatNumericToString, and parsing the formatted String, we introduce a new RenderAmountValueWithPrecision AO that rounds a mathematical value to the requested digits and renders it. CreateFormatterObject is gone, and toString renders through a new RenderAmountValue.

This work is stacked on top of convert-options (#110). The sequence units PR (#161) will be rebuilt on top of it. The refactoring of Number.prototype.toExponential and the promotion of the rounding operations into ECMA-262 will follow as separate PRs.

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://tc39.github.io/proposal-amount/pr-preview/pr-164/

Built to branch gh-pages at 2026-09-29 23:37 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@jessealama
jessealama requested a review from eemeli September 22, 2026 14:25
Base automatically changed from convert-options to main September 28, 2026 01:16
The constructor and convertTo rounded a value by building a formatter
object, calling FormatNumericToString, and parsing the formatted String
back into a mathematical value and a digit count. RenderAmountValueWithPrecision
now rounds the mathematical value itself and renders it. It handles the
sign, rounds to the requested fraction or significant digits with the
same candidate values that ToRawFixed and ToRawPrecision use, turns a
negative value that rounds to zero into negative zero, and renders with
the digit count that the formatted String used to carry, so the stored
Strings are unchanged. CreateFormatterObject is gone.

toString now renders through RenderAmountValue, which contains its
former steps unchanged.
@jessealama
jessealama force-pushed the round-mathematical-values branch from 2db4c7f to 147c8a1 Compare September 29, 2026 23:37

This branch has not been deployed

No deployments
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.

1 participant