1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-23 07:58:09 +00:00

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

This commit is contained in:
Pavol Rusnak 2018-02-06 17:50:36 +01:00
parent 47c598b56e
commit 340f926804
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 10 additions and 2 deletions

View File

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

View File

@ -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):