w2n icon indicating copy to clipboard operation
w2n copied to clipboard

Error on parsing "one half"

Open nielstron opened this issue 6 years ago • 4 comments

>>> from word2number import w2n
>>> w2n.word_to_num("one and one half")
2

Expected output: 1.5

nielstron avatar Sep 02 '18 20:09 nielstron

Thanks for pointing this out. I will look into this ASAP. Meanwhile, you're also welcome to fix the error and submit a Pull Request. If it passes all the tests, it will be merged most probably.

Similar: #30

akshaynagpal avatar Sep 25 '18 18:09 akshaynagpal

Am I correct in thinking that words for fractions (half, third, three quarters etc) are not addressed at all currently ?

jbuzza avatar Jan 31 '19 13:01 jbuzza

It has to do with the way Python rounds numbers. It doesn't always round in the way you would expect, or in this case, rounds by default.

bobbintb avatar Apr 11 '20 19:04 bobbintb

Am I correct in thinking that words for fractions (half, third, three quarters etc) are not addressed at all currently ?

Yes as you can see in the source code, "half", "third" or similar words are never mentioned and hence the corresponding strings also never parsed. This is also why @bobbint there never is any rounding of "half". On the other hand "zero point five" would be correctly parsed as "0.5"

nielstron avatar Apr 14 '20 15:04 nielstron