Add GncNumeric to native Python Fraction

Add helper method to return the native Python fraction type from GncNumeric.
This commit is contained in:
Guy Taylor
2017-05-28 22:13:39 +01:00
committed by John Ralls
parent 1ef379a704
commit e011576e37
2 changed files with 9 additions and 0 deletions

View File

@@ -320,6 +320,10 @@ class GncNumeric(GnuCashCoreClass):
else:
raise TypeError('Required single int/float/str or two ints: ' + str(args))
def to_fraction(self):
from fractions import Fraction
return Fraction(self.num(), self.denom())
def __unicode__(self):
"""Returns a human readable numeric value string as UTF8."""
return gnc_numeric_to_string(self.instance)