akshaynagpal / w2n

Convert number words (eg. twenty one) to numeric digits (21)
http://w2n.readthedocs.io
MIT License
167 stars 78 forks source link

w2n.word_to_num('three point nine seven') 3.9699999999999998 #54

Open yzhang123 opened 3 years ago

yzhang123 commented 3 years ago

list of wrong conversions:

w2n.word_to_num('three point nine seven') ->3.9699999999999998 "two point seven eight" -> 2.7800000000000002 one point eight six -> 1.8599999999999999 two point seven two -> 2.7199999999999998 one point eight four -> 1.8399999999999999 two point two eight->2.2800000000000002 two point four seven->2.4699999999999998 one point five nine->1.5899999999999999

bastie commented 3 years ago

nice floating point converting problem, not really a bug and also not really not a bug

yzhang123 commented 3 years ago

when will this be released?

bastie commented 3 years ago

when will this be released?

I don‘t no. Maybe clone this repository and fix this bug or use w2ni18n fork

00001H commented 3 years ago

I STRONGLY RECOMMEND SWITCHING TO PYTHON3.PYTHON2 IS DEPRECATED AND ONCE THIS GOES BIG IT WILL BE HARDER TO PORT. Use

import decimal
from decimal import Decimal as dcm
decimal.setcontext(decimal.Context(your_precision_here));
x = dcm("1.2349183205012354")#NOTE:STRING!!!
y = dcm(1.39689203452385093)#DOES NOT WORK;LITERAL IS ALREADY OFFSET
z = dcm(240213)#PERFECTLY OK
xx = dcm(13)/dcm(200)#OK TOO.ALL DECIMALS ARE FLOATING POINTS
yy = dcm(13.0/200.0)#BAD!OFFSET RESULT!
print x
##ps:also supports:
print x.sqrt()
print dcm.sqrt(x)
print x*x
print x/x
print x+x
print x-x