From 82e401a77303fca1dc977ee3662d7364bb946ff3 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 16 Nov 2016 10:29:07 +0100 Subject: make fractional base a constant --- src/helpers.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/helpers.ts') diff --git a/src/helpers.ts b/src/helpers.ts index 2e7a701c3..d9b62aa22 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -23,7 +23,7 @@ /// -import {AmountJson} from "./types"; +import {AmountJson, Amounts} from "./types"; import URI = uri.URI; export function substituteFulfillmentUrl(url: string, vars: any) { @@ -34,7 +34,7 @@ export function substituteFulfillmentUrl(url: string, vars: any) { export function amountToPretty(amount: AmountJson): string { - let x = amount.value + amount.fraction / 1e6; + let x = amount.value + amount.fraction / Amounts.fractionalBase; return `${x} ${amount.currency}`; } @@ -63,7 +63,7 @@ export function parsePrettyAmount(pretty: string): AmountJson|undefined { } return { value: parseInt(res[1], 10), - fraction: res[2] ? (parseFloat(`0.${res[2]}`) * 1e-6) : 0, + fraction: res[2] ? (parseFloat(`0.${res[2]}`) / Amounts.fractionalBase) : 0, currency: res[3] } } -- cgit v1.2.3