Fix bugs in the float precision and the currency, increase test coverage (#134)

* Fix some bugs in the float precision and the currency, increase test coverage.

Ref: issue #112 #113

* Update README.rst
This commit is contained in:
Ernesto Rodriguez Ortiz
2017-11-06 20:19:26 -05:00
committed by GitHub
parent 5a131fedc6
commit 1c699d1bb4
15 changed files with 158 additions and 92 deletions

View File

@@ -18,6 +18,7 @@ from __future__ import unicode_literals
import math
from collections import OrderedDict
from decimal import Decimal
from .compat import to_s
@@ -106,6 +107,10 @@ class Num2Word_Base(object):
def float2tuple(self, value):
pre = int(value)
# Simple way of finding decimal places to update the precision
self.precision = abs(Decimal(str(value)).as_tuple().exponent)
post = abs(value - pre) * 10**self.precision
if abs(round(post) - post) < 0.01:
# We generally floor all values beyond our precision (rather than