Skip to content

Commit

Permalink
Update unit.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut authored Sep 13, 2024
1 parent f715482 commit 8246da3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/utils/lib/unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ export const planckToUnit = (val: bigint, units: number): number => {
if (units < 0) {
throw new Error(`Argument out of range: ${units}`)
}
const str = val ? val.toString() : ""
const numb = str.slice(0, str.length - units)
const dec = str.slice(str.length - units)
const result = Number(numb + "." + dec)

const str = val.toString().padStart(units + 1, '0')
// ^^^^^^^^^
const numb = str.slice(0, -units)
const dec = str.slice(-units)
const result = Number(numb + '.' + dec)
return !isNaN(result) ? result : 0
}

Expand Down

0 comments on commit 8246da3

Please sign in to comment.