Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing to_nano function #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions nanopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,20 @@ def to_raw(amount, exp=0):
return str(raw.quantize(_D(1)))


def to_nano(amount, exp=0):
"""Divide amount by 10^exp with precision

:param str amount: amount
:param int exp: positive number
:return: amount divided by 10^exp with appropriate precision
:rtype: str
"""
assert type(amount) is str
exp = exp if exp else standard_exponent
nano = _D(amount) / _D(_D(10) ** exp)
return str(nano.normalize())


def raw_to_nano(amount):
"""Divide a raw amount down by the raw-nano ratio (10^30)

Expand Down