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:
parent
47c598b56e
commit
340f926804
@ -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…
Reference in New Issue
Block a user