def gnc_numeric_to_python_decimal(numeric): negative = numeric.negative_p() sign = 1 if negative else 0 val = GncNumeric(numeric.num(), numeric.denom()) result = val.to_decimal(None) if not result: raise Exception("gnc numeric value {} CAN'T be converted to decimal!".format(val.to_string())) digit_tuple = tuple(int(char) for char in str(val.num()) if char != '-') denominator = val.denom() exponent = int(log10(denominator)) assert( (10 ** exponent) == denominator ) return Decimal((sign, digit_tuple, -exponent))
def gnc_numeric_to_python_Decimal(numeric): negative = numeric.negative_p() if negative: sign = 1 else: sign = 0 copy = GncNumeric(numeric.num(), numeric.denom()) result = copy.to_decimal(None) if not result: raise Exception("gnc numeric value %s can't be converted to decimal" % copy.to_string()) digit_tuple = tuple(int(char) for char in str(copy.num()) if char != '-') denominator = copy.denom() exponent = int(log10(denominator)) assert ((10**exponent) == denominator) return Decimal((sign, digit_tuple, -exponent))
def gnc_numeric_to_python_Decimal(numeric): negative = numeric.negative_p() if negative: sign = 1 else: sign = 0 copy = GncNumeric(numeric.num(), numeric.denom()) result = copy.to_decimal(None) if not result: raise Exception("gnc numeric value %s can't be converted to deciaml" % copy.to_string() ) digit_tuple = tuple( int(char) for char in str(copy.num()) if char != '-' ) denominator = copy.denom() exponent = int(log10(denominator)) assert( (10 ** exponent) == denominator ) return Decimal( (sign, digit_tuple, -exponent) )