Skip to content

Commit

Permalink
fix: string parse in Quantity constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
martonlederer committed Apr 22, 2024
1 parent 8ae7a87 commit d532f97
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Quantity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ export default class Quantity {
this.#qty = base;
break;
case "string":
this.fromString(base);
break;
try {
this.#qty = BigInt(base);
break;
} catch {
throw new Error(
"Could not parse Quantity from string. Make sure to use Quantity.fromString() to load denominated values"
);
}
case "number":
if (!Number.isInteger(base)) {
throw new Error("Cannot create Quantity from a non-integer number");
Expand Down

0 comments on commit d532f97

Please sign in to comment.