Skip to content

Commit

Permalink
last-partizan#23 fix floats with both of dot and mantissa
Browse files Browse the repository at this point in the history
  • Loading branch information
Pentusha committed Nov 27, 2014
1 parent 7ed710d commit cfab120
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pytils/numeral.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ def _get_float_remainder(fvalue, signs=9):

# нужно remainder в строке, потому что дробные X.0Y
# будут "ломаться" до X.Y
try:
remainder = str(fvalue).split('.')[1]
except IndexError:
if 'e' in str(fvalue).lower():
remainder = str(Decimal(str(fvalue))).split('.')[1]
else:
remainder = str(fvalue).split('.')[1]

iremainder = int(remainder)
orig_remainder = remainder
factor = len(str(remainder)) - signs
Expand Down
2 changes: 2 additions & 0 deletions pytils/test/test_numeral.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ def testFloat(self):
u"ноль целых одна стотысячная")
self.assertEquals(pytils.numeral.in_words_float(2e-6),
u"ноль целых две милллионных")
self.assertEquals(pytils.numeral.in_words_float(2.5e-6),
u"ноль целых двадцать пять десятимиллионных")

def testDecimal(self):
"""
Expand Down

0 comments on commit cfab120

Please sign in to comment.