Re: PHP 4.2.2 Float->Mysql addition problem
| From: | Andrei | Date: | Fri, 03 Feb 2006 11:24:56 +0000 |
| Subject: | Re: PHP 4.2.2 Float->Mysql addition problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-229797@lists.php.net to get a copy of this message | ||
When working with floats with php/mysql I had problems too... When summing amounts I had errors so my solution was using decimal (20, 10) type into mysql for storing amounts and when using sums in php I used bc functions. This way u get exact calculations (depending on bcscale() parameter.
Andy
Barry wrote:
Hi List ^_^ PHP 4.2.2 Redhat 7.3 Mysql 3.23.54 Ok here is the problem: I try to summary float values from my database (mysql) in PHP. code: $sql = "SELECT * FROM somwehere WHERE 1"; $result = mysql_query($sql); while ($assoc = mysql_fetch_assoc($result)) {//adding values $sum = $sum + $assoc["floatval"];} echo $sum; // echoes an INTEGER VALUE O_o echoing the mysql value it is float like "123.45" The type of the mysql value is "string" setting the type to float doesnt help (settype()) Any ideas? GreetsBarry