You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here 1 with 9 time 0, and a precision of 10, returns 1 with 9 times 0. Although it should return "0.1" planckToUnit(1000000000, 10).toLocaleString('en') return 1,000,000,000 although it should return
Got some better results with the following, but I'd advise to look online for something battletested, no need to reinvent it:
export const planckToUnit = (val: bigint, units: number): number => {
if (units < 0) {
throw new Error(`Argument out of range: ${units}`)
}
const str = val.toString().padStart(units + 1, '0')
// ^^^^^^^^^
const numb = str.slice(0, -units)
const dec = str.slice(-units)
const result = Number(numb + '.' + dec)
const res = !isNaN(result) ? result : 0
return res
}
The text was updated successfully, but these errors were encountered:
Here 1 with 9 time 0, and a precision of 10, returns 1 with 9 times 0. Although it should return "0.1"
planckToUnit(1000000000, 10).toLocaleString('en')
return1,000,000,000
although it should returnGot some better results with the following, but I'd advise to look online for something battletested, no need to reinvent it:
The text was updated successfully, but these errors were encountered: