Re: PHP 4.2.2 Float->Mysql addition problem
| From: | Barry | Date: | Mon, 06 Feb 2006 08:40:42 +0000 |
| Subject: | Re: PHP 4.2.2 Float->Mysql addition problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-229930@lists.php.net to get a copy of this message | ||
Hi!
I forget the rules of float contagion in PHP, but it "should" work, I would expect...That's what i also did, though.
I don't suppose that by sheer chance the decimal portions add up to an even integer?... 0.3333 + 0.6666 might, for example, turn into: 1 (Or might not, depending on a low-level float implementation)It prints out 0.9999
Some other options: Cast them in MySQl and let MySQL add them up.Works fine, just needs 3 seconds for the query. 3 seconds for the table + 3 seconds for the summary. This is taking a bit to long ;)
I forget MySQL's typecast operator/function, but it's in the manual: http://dev.mysql.com Something like: select sum(cast(floatval, 'decimal')) from somewhere You may also need to use coalesce to change NULL into 0. You'd have to tell use what the actual string values ARE for us to do any more than guess, though.Normal prices like: 345.76 234.09 324.54 And so on Greets Barry -- Smileys rule (cX.x)C --o(^_^o) Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)