apps/wallet+apps/ethereum: fix formatting of amounts (avoid using float)

pull/25/head
Pavol Rusnak 7 years ago
parent 47c598b56e
commit 340f926804
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -48,4 +48,8 @@ def format_amount(value, token, chain_id):
decimals = 18
suffix = networks.suffix_by_chain_id(chain_id)
return '%s %s' % (value // 10 ** decimals, suffix)
d = pow(10, decimals)
value = ('%d.%0*d' % (value // d , decimals, value % d)).rstrip('0')
if value.endswith('.'):
value += '0'
return '%s %s' % (value, suffix)

@ -8,7 +8,11 @@ from apps.common.confirm import hold_to_confirm
def format_amount(amount, coin):
return '%s %s' % (amount / 1e8, coin.coin_shortcut)
d = pow(10, 8)
amount = ('%d.%08d' % (amount // d , amount % d)).rstrip('0')
if amount.endswith('.'):
amount += '0'
return '%s %s' % (amount, coin.coin_shortcut)
def split_address(address):

Loading…
Cancel
Save