Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.16.4

Bug #14988 Non-int parsing returns bogus result
Submitted: 2008-11-10 19:52 UTC Modified: 2009-03-10 18:00 UTC
From: cfankhauser Assigned: doconnor
Status: Closed Package: Numbers_Words (version 0.15.0)
PHP Version: 5.2.6 OS: OSX
Roadmaps: (Not assigned)    
Subscription  


 [2008-11-10 19:52 UTC] cfankhauser (Chris Fankhauser)
Description: ------------ When passing a non-int to toWords (e.g. 10.5 or 10abc3) all non-numeric characters are cast to int, replacing it with a zero. So, 10.5 becomes 1005 and 10abc3 becomes 100,003 -- both clearly misrepresenting the values passed to the function. Expected result: ---------------- When passed a float, I would expect one of two things: a) 10.5 (for example) is split on the period, and toWords is recursively run on 10, then 5, and the two are concatenated with the word "point". b) the value is simply cast to int, discarding everything including and to the right of the decimal. When passed an alphanumeric string, I would expect one of two things: a) any non-numeric characters to be stripped out. 10abc3 would become 103. b) the value is simply cast to int, discarding everything from and including the first non-numeric character to the right. 10abc3 would become 10. Actual result: -------------- Currently: 10.5 results in 1005 being parsed, yielding one thousand five. 10abc3 results in 100003 being parsed, yielding one hundred thousand three.

Comments

 [2008-11-16 08:00 UTC] cweiske (Christian Weiske)
I also have a testcase lying around here.
 [2008-11-24 08:44 UTC] doconnor (Daniel O'Connor)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.
 [2008-11-24 22:24 UTC] doconnor (Daniel O'Connor)
Looking at other files, particularly lang.es_AR.php; theres been a slightly different approach it looks like. Namely if ($dec) { $dec = $this->toWords(trim($dec)); $ret .= ' con ' . trim ($dec); }
 [2009-03-10 18:00 UTC] kouber (Kouber Saparev)
It appears that the bug fix introduced an uncoditional cast to int, which broke passing of bigger numbers. Committed a fix fo that in CVS.