Skip to content

toFixed gives incorrect results in some cases #1511

@bterlson

Description

@bterlson

Repro:

print(1.25499999999999989342.toFixed(2));
print(1.255.toFixed(2));

/*
┌─────────────────────┬──────┐
│ chakra-es6          │ 1.26 │
│ chakra-experimental │ 1.26 │
│ chakra              │      │
├─────────────────────┼──────┤
│ jsc                 │ 1.25 │
│ sm                  │ 1.25 │
│ d8                  │      │
└─────────────────────┴──────┘
*/

Expected: 1.25
Actual: 1.26

Other engines seem to get this correct, so we also have an interop issue. I recall that this has come up a lot in the past but I can't find history on GitHub :(

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions