tc39 / tc39/proposal-amount

Type of the non-final entries of an Array `.value` when precision is applied in constructor

Open
#142 2 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

Splitting off from #141 , where the suggestion was that if fractionDigits is supplied as an option in the constructor, we need to make a decision about the types of the entries in the store .value array, in particular the non-final ones. Example:

let a = new Amount([5, 11.1], { unit: "foot-and-inch", fractionDigits: 0 })

Should a.value be [5, "1.1e+1"] or ["5e+0", "1.1e+1"]?

Storing only the last entry as a decimal-digit string matches the rule that an input numeric value gets stringified when precision is applied to it. The earlier entries are required* to be integers, so they carry no precision information. Following the "stop coercing things" philosophy, an input Number stays a Number. The result is the mixed array [5, "1.1e+1"].

(* This argument assumes that the only units we support in sequence units are always integer multiples of one another, starting from the smallest to the biggest. That should be safe to assume but perhaps there are counterexamples.)

On the other hand, the "precision specified --> stringify" principle could be understood as applying to each component of the argument, even if it requires us to put an integral Number in quotes. Moreover, there may be something to be said for favoring uniform arrays. Thus, we ought to store ["5e+0", "1.1e+1"].

We need to decide which principles we want to stick to in the context of sequence units and make a decision. Presumably the same logic ought to apply to .convertTo, too.

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

Read the discussion in #141 and compare the constructor's precision behavior with the proposed .value representations for sequence units. Then examine how .convertTo should follow the same rule. Done means the project has decided and documented whether non-final entries remain Numbers or are stringified.

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
Quiet
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.