Fix/tweak numbers implementation

Round fixed point decimals in initialiser to match Python behaviour
Add pretty printing for Python
This commit is contained in:
RunasSudo 2021-01-02 23:33:47 +11:00
parent 15dd93cf24
commit 8a304aedcf
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
4 changed files with 7 additions and 1 deletions

View File

@ -28,7 +28,7 @@ class Fixed:
if isinstance(val, Fixed):
self.impl = val.impl
else:
self.impl = Big(val)
self.impl = Big(val).round(Big.DP)
def pp(self, dp):
"""Pretty print to specified number of decimal places"""

View File

@ -34,6 +34,8 @@ class Fixed:
else:
self.impl = Decimal(val).quantize(_quantize_exp)
def __repr__(self):
return '<Fixed {}>'.format(str(self.impl))
def pp(self, dp):
"""Pretty print to specified number of decimal places"""
return format(self.impl, '.{}f'.format(dp))

View File

@ -27,6 +27,8 @@ class Native:
else:
self.impl = float(val)
def __repr__(self):
return '<Native {}>'.format(str(self.impl))
def pp(self, dp):
"""Pretty print to specified number of decimal places"""
return format(self.impl, '.{}f'.format(dp))

View File

@ -28,6 +28,8 @@ class Rational:
else:
self.impl = Fraction(val)
def __repr__(self):
return '<Rational {}>'.format(str(self.impl))
def pp(self, dp):
"""
Pretty print to specified number of decimal places