1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-27 10:48:22 +00:00

convert comma to dot as a decimal separator

This commit is contained in:
slowbackspace 2019-03-12 13:55:13 +01:00
parent b722b8d86a
commit 93bea9d195

View File

@ -2,7 +2,7 @@ import BigNumber from 'bignumber.js';
const toFiatCurrency = (amount, fiatCurrency, networkRates) => {
// calculate amount in local currency
if (!networkRates || !networkRates.rates) {
if (!networkRates || !networkRates.rates || !amount) {
return '';
}
@ -11,13 +11,15 @@ const toFiatCurrency = (amount, fiatCurrency, networkRates) => {
return '';
}
let localAmount = BigNumber(amount).times(rate);
const formattedAmount = amount.replace(',', '.');
let localAmount = BigNumber(formattedAmount).times(rate);
localAmount = localAmount.isNaN() ? '' : localAmount.toFixed(2);
return localAmount;
};
const fromFiatCurrency = (localAmount, fiatCurrency, networkRates, decimals) => {
if (!networkRates || !networkRates.rates) {
if (!networkRates || !networkRates.rates || !localAmount) {
return '';
}
@ -26,7 +28,9 @@ const fromFiatCurrency = (localAmount, fiatCurrency, networkRates, decimals) =>
return '';
}
let amount = BigNumber(localAmount).div(rate);
const formattedLocalAmount = localAmount.replace(',', '.');
let amount = BigNumber(formattedLocalAmount).div(rate);
amount = amount.isNaN() ? '' : amount.toFixed(decimals);
return amount;
};