mirror of
https://github.com/autistic-symposium/web3-starter-py.git
synced 2025-05-17 14:10:21 -04:00
💾
This commit is contained in:
parent
0696b08d04
commit
314bdf533e
94 changed files with 11 additions and 7 deletions
25
web3-toolkit/scripts/utils/arithmetics.py
Normal file
25
web3-toolkit/scripts/utils/arithmetics.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
# arithmetics.py
|
||||
# This class implements math methods used by the other classes.
|
||||
# author: steinkirch
|
||||
|
||||
|
||||
from decimal import Decimal, getcontext
|
||||
from utils.strings import log_error
|
||||
|
||||
|
||||
def div(dividend, divisor) -> Decimal:
|
||||
"""Return higher precision division."""
|
||||
|
||||
if divisor == 0:
|
||||
log_error('Found a zero division error. Returning 0.')
|
||||
return 0
|
||||
return to_decimal(dividend) / to_decimal(divisor)
|
||||
|
||||
|
||||
def to_decimal(value, precision=None) -> Decimal:
|
||||
"""Return Decimal value for higher (defined) precision."""
|
||||
|
||||
precision = precision or 22
|
||||
getcontext().prec = precision
|
||||
return Decimal(value)
|
Loading…
Add table
Add a link
Reference in a new issue