Skip to content

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

Closed
@amoshydra

Description

@amoshydra

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions