Skip to content

Commit d10d41b

Browse files
committed
fixed
1 parent 74f1398 commit d10d41b

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/libs/fixed/fixed.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ test("fixed", async () => {
77
assert(Fixed.fromDecimalString("0.1", 2).value === 10n)
88
assert(Fixed.fromDecimalString(".1", 2).value === 10n)
99
assert(Fixed.fromDecimalString(".", 2).value === 0n)
10+
assert(Fixed.fromDecimalString("0", 2).value === 0n)
1011
})

src/libs/fixed/fixed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class Fixed<D extends number = number> {
7878
}
7979

8080
static fromDecimalString<D extends number>(text: string, decimals: D) {
81-
const [whole, decimal] = text.split(".")
81+
const [whole = "0", decimal = "0"] = text.split(".")
8282
const value = BigInt(whole + decimal.padEnd(decimals, "0").slice(0, decimals))
8383
return new Fixed(value, decimals)
8484
}

0 commit comments

Comments
 (0)