tc39 / tc39/proposal-decimal

How should the BigDecimal constructor round Numbers?

Open
#40 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
638
Forks
20
PR merge metrics
No merged PRs in 30d

Description

A couple options, suggested by Fabrice Bellard:

(1) BigDecimal(0.1) = 0.1d (i.e. use Number.prototype.toString() and then convert the string to bigdecimal).

(2) BigDecimal(0.1) = 0.1000000000000000055511151231257827021181583404541015625d

(2) is mathematically correct but may be surprising, so I selected (1).

I have to say, I was really expecting (2), but (1) may be more practical. One way to think of a Number is an exact quantity, and another way is to think of it as a range within the ulp.

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 issue discussion and compare the two proposed BigDecimal constructor behaviors for Number values. The issue does not name files, tests, or an implementation entry point; done would require a decided rounding rule and corresponding project changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data
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.