You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
846 B
43 lines
846 B
5 years ago
|
from decimal import Decimal
|
||
|
|
||
|
|
||
|
_conversion_unit = Decimal(1e18)
|
||
|
|
||
|
def convert_atto_to_one(atto):
|
||
|
"""
|
||
|
Convert ATTO to ONE
|
||
|
|
||
|
Parameters
|
||
|
----------
|
||
|
atto: str, int, float, decimal
|
||
|
Value in ATTO to convert to ONE
|
||
|
Float input will be truncated, since ATTO is the lowest possible denomination of ONE
|
||
|
|
||
|
Returns
|
||
|
-------
|
||
|
decimal
|
||
|
Converted value in ONE
|
||
|
"""
|
||
|
if isinstance(atto, float):
|
||
|
atto = int(atto)
|
||
|
return Decimal(atto) / _conversion_unit
|
||
|
|
||
|
|
||
|
def convert_one_to_atto(one):
|
||
|
"""
|
||
|
Convert ONE to ATTO
|
||
|
|
||
|
Parameters
|
||
|
----------
|
||
|
one: str, int, float, decimal
|
||
|
Value in ONE to convert to ATTO
|
||
|
|
||
|
Returns
|
||
|
-------
|
||
|
decimal
|
||
|
Converted value in ATTO
|
||
|
"""
|
||
|
if isinstance(one, float):
|
||
|
one = str(one)
|
||
|
return Decimal(one) * _conversion_unit
|