Re: PHP 4.2.2 Float->Mysql addition problem
| From: | Andrei | Date: | Fri, 03 Feb 2006 14:47:12 +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-229807@lists.php.net to get a copy of this message | ||
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."<br>";} else {
echo "false: c = ".$c."<br>";} var_dump((bool) "0"); It's a common use to do if( $var ) and not if( (bool)$var )... Andy Ford, Mike wrote:
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 ) {Er - nope. The string "0" is explicitly equivalent to FALSE -- see http://www.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: m.ford@leedsmet.ac.uk...} 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 interpreted like a string that is not null and so condition is interpreted as true.Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm