Skip to content

Fix Number.prototype.toExponential() value rounding #4169

@HalidOdat

Description

@HalidOdat

Describe the bug

The output is incorrect when rounding with 5 as the last digit.

(25).toExponential(0), // Should return "3e+1", actual "2e+1"
(12345).toExponential(3) // Should return "1.235e+4", actual "1.234e+4"

This cause the last built-in Number test262 test to fail: https://github.com/tc39/test262/blob/main/test/built-ins/Number/prototype/toExponential/return-values.js

Already have the issue in the ryu-js crate boa-dev/ryu-js#31, just leaving this issue to avoid duplicate work, trying to fix the hacky solution with format! 😅

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions