This commit is contained in:
2026-05-18 13:06:12 +08:00
parent 94bcbc8d8f
commit c2020af3bf
2 changed files with 3 additions and 3 deletions

View File

@@ -3,14 +3,14 @@ export function safeTruncate(num, decimals = 2) {
return '0.00'
const factor = 10 ** decimals
const scaled = Math.trunc(num * factor)
const scaled = Math.round(num * factor)
return (scaled / factor).toFixed(decimals)
}
function toTruncatedCents(num) {
if (Number.isNaN(num) || !Number.isFinite(num))
return 0
return Math.trunc((num + Number.EPSILON) * 100)
return Math.round(num * 100)
}
function centsToFixed(cents) {