diff options
author | Kevin Serrano <kevgagser@gmail.com> | 2016-08-19 06:59:37 +0800 |
---|---|---|
committer | Kevin Serrano <kevgagser@gmail.com> | 2016-08-19 06:59:37 +0800 |
commit | 4cebf12bb51fba192a59eb550d34c9cf8b31a761 (patch) | |
tree | 76945e0cd8ad80841e1af65ee955b6e52b51ca5f /ui/app/util.js | |
parent | 90d6bec3ed51ba4b2d4696132642a4d97712dec9 (diff) | |
download | tangerine-wallet-browser-4cebf12bb51fba192a59eb550d34c9cf8b31a761.tar tangerine-wallet-browser-4cebf12bb51fba192a59eb550d34c9cf8b31a761.tar.gz tangerine-wallet-browser-4cebf12bb51fba192a59eb550d34c9cf8b31a761.tar.bz2 tangerine-wallet-browser-4cebf12bb51fba192a59eb550d34c9cf8b31a761.tar.lz tangerine-wallet-browser-4cebf12bb51fba192a59eb550d34c9cf8b31a761.tar.xz tangerine-wallet-browser-4cebf12bb51fba192a59eb550d34c9cf8b31a761.tar.zst tangerine-wallet-browser-4cebf12bb51fba192a59eb550d34c9cf8b31a761.zip |
Fix rounding issues.
Diffstat (limited to 'ui/app/util.js')
-rw-r--r-- | ui/app/util.js | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/ui/app/util.js b/ui/app/util.js index e1fd6e399..ce52348c8 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -141,16 +141,21 @@ function shortenBalance (balance, decimalsToKeep = 1) { var convertedBalance = parseFloat(balance) if (convertedBalance > 1000000) { truncatedValue = (balance / 1000000).toFixed(decimalsToKeep) - return `>${truncatedValue}m` + return `${truncatedValue}m` } else if (convertedBalance > 1000) { truncatedValue = (balance / 1000).toFixed(decimalsToKeep) - return `>${truncatedValue}k` + return `${truncatedValue}k` } else if (convertedBalance === 0) { return '0' - } else if (convertedBalance < 1) { - var exponent = balance.match(/\.0*/)[0].length - truncatedValue = (convertedBalance * Math.pow(10, exponent)).toFixed(decimalsToKeep) - return `<${truncatedValue}e-${exponent}` + } else if (convertedBalance < 0.001) { + return '<0.001' + } else if (convertedBalance < 1) { + var stringBalance = convertedBalance.toString() + if (stringBalance.split('.')[1].length > 3) { + return convertedBalance.toFixed(3); + } else { + return stringBalance + } } else { return convertedBalance.toFixed(decimalsToKeep) } |