fix: improve round function; improvement to #873 (#901)

This commit is contained in:
Timmy Braun
2026-06-22 20:07:27 +08:00
committed by GitHub
parent 5c3522f339
commit 956b51ea95
2 changed files with 6 additions and 3 deletions
+2 -3
View File
@@ -15,7 +15,6 @@ export function round (v: number, arg = 0) {
v = toNumber(v)
arg = toNumber(arg)
const amp = Math.pow(10, arg)
const scaled = v * amp
// Round half away from zero
return Math.sign(v) * Math.round(Math.abs(scaled)) / amp
const scaled = (v * amp) * (1 + Number.EPSILON)
return Math.round(scaled) / amp
}