aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util/src/amounts.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-06-20 11:50:04 -0300
committerSebastian <sebasjm@gmail.com>2023-06-20 11:50:34 -0300
commit9f07ab8d4a13d52d7fd61a3e9b8ddc423fee164e (patch)
treeb14a56a1e1e46c89b4e8d7090bf2f4380f31be18 /packages/taler-util/src/amounts.ts
parentac9b4bfd0edc8d4f8c396837d2192fb6895e5b29 (diff)
downloadwallet-core-9f07ab8d4a13d52d7fd61a3e9b8ddc423fee164e.tar.xz
remove from float
Diffstat (limited to 'packages/taler-util/src/amounts.ts')
-rw-r--r--packages/taler-util/src/amounts.ts26
1 files changed, 7 insertions, 19 deletions
diff --git a/packages/taler-util/src/amounts.ts b/packages/taler-util/src/amounts.ts
index a998c8f63..a8df3679f 100644
--- a/packages/taler-util/src/amounts.ts
+++ b/packages/taler-util/src/amounts.ts
@@ -147,8 +147,10 @@ export class Amounts {
throw Error(`incompatible currency (${am1.currency} vs${am2.currency})`);
}
- const x1 = BigInt(am1.value) * BigInt(amountFractionalBase) + BigInt(am1.fraction);
- const x2 = BigInt(am2.value) * BigInt(amountFractionalBase) + BigInt(am2.fraction);
+ const x1 =
+ BigInt(am1.value) * BigInt(amountFractionalBase) + BigInt(am1.fraction);
+ const x2 =
+ BigInt(am2.value) * BigInt(amountFractionalBase) + BigInt(am2.fraction);
const quotient = x1 / x2;
const remainderScaled = x1 % x2;
@@ -158,9 +160,9 @@ export class Amounts {
remainder: {
currency: am1.currency,
value: Number(remainderScaled / BigInt(amountFractionalBase)),
- fraction: Number(remainderScaled % BigInt(amountFractionalBase))
- }
- }
+ fraction: Number(remainderScaled % BigInt(amountFractionalBase)),
+ },
+ };
}
static sum(amounts: AmountLike[]): Result {
@@ -391,20 +393,6 @@ export class Amounts {
}
}
- /**
- * Convert a float to a Taler amount.
- * Loss of precision possible.
- */
- static fromFloat(floatVal: number, currency: string): AmountJson {
- return {
- currency,
- fraction: Math.floor(
- (floatVal - Math.floor(floatVal)) * amountFractionalBase,
- ),
- value: Math.floor(floatVal),
- };
- }
-
static min(a: AmountLike, b: AmountLike): AmountJson {
const cr = Amounts.cmp(a, b);
if (cr >= 0) {