Open Siddhant opened 9 years ago
And this I expected to throw an error:
>>> p.number_to_words('1213jfkjsdn34235jnjn3432')
'one trillion, two hundred and thirteen billion, three hundred and forty-two million, three hundred and fifty-three thousand, four hundred and thirty-two'
number_to_words()
strips out all non-numeric characters, presumably to clean up commas, while ordinal()
accepts non-numeric numbers (i.e. 'forty') and thus cannot do that in the same way. Both functions could stand some improvement.
>>> p.number_to_words('11 11')
'one thousand, one hundred and eleven'
This is probably the right thing to do.
Numbers can for example have commas for thousands separators (UK), fullstops (France), or spaces (scientific use). See http://wordpress.mrreid.org/2014/05/27/stop-putting-commas-in-your-numbers/
So it's probably best for the user to decide how to split text before giving it to number_to_words()
.
Perhaps ordinal()
should also strip out non-numeric characters as well.
While number_to_words is removing all intervening spaces, ordinal ain't doing the same. Why the inconsistency? Why isn't number_to_words complaining about the space?