Skip to content

Commit

Permalink
feat: improve integer() and fractional() to not use strings
Browse files Browse the repository at this point in the history
  • Loading branch information
martonlederer committed Apr 11, 2024
1 parent 410f53b commit 98b6d61
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/Quantity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,14 @@ export default class Quantity {
* Integer/whole part
*/
get integer() {
const qtyStr = this.#qty.toString();
return BigInt(
qtyStr.slice(0, qtyStr.length - Number(this.#D))
);
return this.#qty / 10n ** this.#D;
}

/**
* Fractional part in integers
*/
get fractional() {
const qtyStr = this.#qty.toString();
return BigInt(
qtyStr.slice(qtyStr.length - Number(this.#D), qtyStr.length)
);
return this.#qty - this.integer * 10n ** this.#D;
}

/**
Expand Down

0 comments on commit 98b6d61

Please sign in to comment.