mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 14:52:25 +00:00
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:
committed by
GitHub
parent
5a131fedc6
commit
1c699d1bb4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user