From 076819d009e9ca5fc161306c15c6b78d63d4abda Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Wed, 27 Jun 2018 16:24:26 -0700 Subject: [PATCH] currencyservice: fix nanos overflow due to rounding Signed-off-by: Ahmet Alp Balkan --- src/currencyservice/server.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/currencyservice/server.js b/src/currencyservice/server.js index a1429d8..7cd6539 100644 --- a/src/currencyservice/server.js +++ b/src/currencyservice/server.js @@ -95,19 +95,24 @@ function convert (call, callback) { nanos: from.nanos / data[from.currency_code] }); + euros.nanos = Math.round(euros.nanos); + // Convert: EUR --> to_currency const result = _carry({ units: euros.units * data[request.to_code], nanos: euros.nanos * data[request.to_code] }); - result.nanos = Math.round(result.nanos); + + result.units = Math.floor(result.units) + result.nanos = Math.floor(result.nanos) result.currency_code = request.to_code; - console.log('Conversion request successful.'); + console.log(`Conversion request successful ${result.nanos}..${result.nanos}`); callback(null, result); }); } catch (err) { console.error('Conversion request failed.'); + console.error(err); callback(err.message); } }