Skip to content

fix(round): avoid floating point precision issues when rounding - #2227

Open
TbhVishal wants to merge 1 commit into
toss:mainfrom
TbhVishal:fix/round-precision
Open

TbhVishal wants to merge 1 commit into
toss:mainfrom
TbhVishal:fix/round-precision

Conversation

@TbhVishal

Copy link
Copy Markdown

Fixes #2225

Multiplying by powers of 10 causes floating point inaccuracies for numbers like 1.005 with precision 2.

Swapped the multiplier for exponential notation shifting, similar to how compat handles decimal adjustment. Also keeps -0 and non-finite numbers intact.

Can test locally with: yarn vitest run src/math/round.spec.ts

@vercel

vercel Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
es-toolkit Ready Ready Preview Nov 19, 2026 4:03am UTC

Request Review

This branch was successfully deployed

1 active deployment
Preview — 0791f052 Deployed Nov 19, 2026 by vercel[bot]
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

Successfully merging this pull request may close these issues.

round(1.005, 2) returns 1, while es-toolkit/compat returns 1.01

1 participant