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

$string(number) capped at precision-15 #669

Open
grant-d opened this issue Jan 29, 2024 · 0 comments
Open

$string(number) capped at precision-15 #669

grant-d opened this issue Jan 29, 2024 · 0 comments

Comments

@grant-d
Copy link

grant-d commented Jan 29, 2024

We have some integers (below the safe limit of 2^53 - 1) that are being rounded to precision 15 once we use $string() on them.
This seems due to the following line of code, specifically the positive unary case, ? Number(val.toPrecision(15))

return (typeof val !== 'undefined' && val !== null && val.toPrecision && isNumeric(val)) ? Number(val.toPrecision(15)) :

I can submit a PR but my question is whether there is a good reason for the limit. I would not want to regress something else.

Repro:

$string(1e15 - 1) //  999...999 (15 digits, correct result)
$string(1e15    ) // 1000...000 (16 digits, correct result)
$string(1e15 + 1) // 1000...000 (16 digits, wrong result - notice no trailing 1)

// For completeness, Number.MAX_SAFE_INTEGER = 2^53-1 = 9,007,199,254,740,991 = ~1e16
$string(9007199254740991) // 9007199254740990 (16 digits, wrong result - notice rounding on last digit)
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