tc39 / tc39/proposal-amount

Formatting with increased precision seems like an error case

Open
#49 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
58
Forks
12
Avg merge
2h 35m
Merged PRs (30d)
2

Description

const d = new Amount(1.23456, { significantDigits: 2 });

d.toString() // '1.2'

d.with({ significantDigits: 4 }).toString() // '1.200' or '1.235'?

From today's presentation, we discussed what should happen when formatting with a higher precision that the input's precision. I think we came to an agreement 1.235 is incorrect. But I think even 1.200 is incorrect, it implies a precision which is not captured in our input.

Quoting a bit from wikipedia:

The following types of digits are not considered significant:

  • Spurious digits that arise from calculations resulting in a higher precision than the original data or a measurement reported with greater precision than the instrument's resolution. link

As an example, the amount we hvae is the calculation of some operation. Eg, if we had a * b === 1.23456, with a = 2.46912 and b = 2.0. Even though the calculation has a precision precision of 6, the actual amount represented here only contains 2. It is incorrect to ever print this value as 1.23456 because I am only certain of the first 2 digits.

I would accept d.with(4).toString() as 1.2, making it very clear that we cannot create more precision from an amount that doesn't have that to begin with. But 1.200 seems wrong, because we have no idea what those 00 should be.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Amount.with and toString entry points shown in the issue, and review the discussion about formatting above the input precision. The work is done when the project has an agreed rule for this case and the resulting output is specified and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.