currencyservice: fix nanos overflow due to rounding

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2018-06-27 16:24:26 -07:00 committed by Simon Zeltser
parent 6f10ac9794
commit 076819d009

View file

@ -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);
}
}