Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the behavior of the constructor when a decimal exceeding 34 decimal places is provided #184

Open
amoshydra opened this issue Jan 8, 2025 · 0 comments

Comments

@amoshydra
Copy link

amoshydra commented Jan 8, 2025

Question

What is the expected behavior for the following inputs?

new Decimal("0.1000000000_0000000000_0000000000_1111_4")
new Decimal("0.1000000000_0000000000_0000000000_1111_5")
new Decimal("0.1000000000_0000000000_0000000000_1111_6")
new Decimal("0.1000000000_0000000000_0000000000_1112_4")
new Decimal("0.1000000000_0000000000_0000000000_1112_5")
new Decimal("0.1000000000_0000000000_0000000000_1112_6")

The decimal inputs above has 35 decimals and 35 significant decimals

  1. Should the specification define the behavior for such input?
  2. If yes, should it be:
    1. undefined, thus up to implementor?
    2. truncate?
    3. round halfEven?
    4. throw error?

From my reading, currently specification only mention ParseText, but ParseText does not provide detail on how such input should be handled.

Image

Ref: https://tc39.es/proposal-decimal/#sec-the-decimal128-constructor-value

Side note

the npm package decimal128 @ 22:

new Decimal("0.00000_0000000000_9999999999_9999999999_9999999999_99915").toString() 
x v
input "0.00000_0000000000_9999999999_9999999999_9999999999_99915"
current "0.00000_0000000001"
expected "0.00000_0000000000_9999999999_9999999999_9999999999_9992"

^ expectation assuming round halfEven

@amoshydra amoshydra changed the title What is the behaviour of constructor when a decimal exceeding 34 decimal places is provided What is the behavior of the constructor when a decimal exceeding 34 decimal places is provided Jan 8, 2025
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

No branches or pull requests

1 participant