Re: [PHP] PHP 4.2.2 Float->Mysql addition problem

2006-02-06 Thread Barry
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. + 0. >might, for example, turn into: 1 >(Or might not, depending on a

Re: [PHP] PHP 4.2.2 Float->Mysql addition problem

2006-02-03 Thread Richard Lynch
It's possible that MySQL has larger range of floats than PHP. Then when your numbers come in, PHP ends up making them be things like: 'NaN' (not a number) or '6.02e+23' or ... There are a LOT of ways to represent floats in such a way that you can confuse the heck out of PHP and MySQL between th

Re: [PHP] PHP 4.2.2 Float->Mysql addition problem

2006-02-03 Thread Andrei
Actually we'r talking about diffrent things... What I wanted to highlight is that results that should be normally seen as 0 or false for logic comparations when using bc functions are not processed as 0 or false actually and you should take care when using constructs like if( $var ) { ..

Re: [PHP] PHP 4.2.2 Float->Mysql addition problem

2006-02-03 Thread Andrei
Er - yes. If you do conversion type you are correct. but in the example I showed I didn't... If you run the code bellow you will see... bcscale( 10 ); $a = 14.5; $b = -14.5; $c = bcadd( $a, $b ); if( $c ) { echo "true: c = ".$c.""; } else { echo "false: c = ".$c.""; } var_dump((bool) "

RE: [PHP] PHP 4.2.2 Float->Mysql addition problem

2006-02-03 Thread Ford, Mike
On 03 February 2006 13:14, Andrei wrote: > Welcome, > Please note that using bc function variables will be of type string. > So a code working with numeric values like: > > $a = 1; > if( $a ) > { > ... > } > > it's ok but with bc functions: > > $a = 14.5; > $b = -14.5; > $c = bcadd( $a, $b

Re: [PHP] PHP 4.2.2 Float->Mysql addition problem

2006-02-03 Thread Andrei
Welcome, Please note that using bc function variables will be of type string. So a code working with numeric values like: $a = 1; if( $a ) { ... } it's ok but with bc functions: $a = 14.5; $b = -14.5; $c = bcadd( $a, $b ); if( $c ) { ... } will not work as expected ( if( "0" ) is inte

Re: [PHP] PHP 4.2.2 Float->Mysql addition problem

2006-02-03 Thread Barry
Barry wrote: Andrei wrote: 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 (depen

Re: [PHP] PHP 4.2.2 Float->Mysql addition problem

2006-02-03 Thread Barry
Andrei wrote: 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

Re: [PHP] PHP 4.2.2 Float->Mysql addition problem

2006-02-03 Thread Andrei
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.

[PHP] PHP 4.2.2 Float->Mysql addition problem

2006-02-03 Thread Barry
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