Author Topic: php inequalities problem  (Read 829 times)

0 Members and 1 Guest are viewing this topic.

Offline RenlokTopic starter

  • Enthusiast
  • Posts: 253
  • Gender: Male
    • View Profile
    • WeLink
php inequalities problem
« on: February 25, 2010, 08:34:44 AM »
i have an if statement
if ($bid $next_bid)
and it $bid & $next_bid hold the same values. php seems to think the statement is true.

is this a bug in php or something?

Offline PFMaBiSmAd

  • Guru
  • 'Insane!'
  • *
  • Posts: 14,588
  • In Coding, Automatic means you write code to do it
    • View Profile
Re: php inequalities problem
« Reply #1 on: February 25, 2010, 08:39:15 AM »
What does the following show (i.e. you are asking someone to attempt to tell you why a comparison is not working without any information about the actual values being compared) -

var_dump
($bid);
echo 
'<br />';
var_dump($next_bid);
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

Offline RenlokTopic starter

  • Enthusiast
  • Posts: 253
  • Gender: Male
    • View Profile
    • WeLink
Re: php inequalities problem
« Reply #2 on: February 25, 2010, 08:57:11 AM »
It shows
string(4) "0.29"
float(0.29)

EDIT:
but even if i change it to
var_dump(floatval($bid));
echo 
'<br />';
var_dump($next_bid);
if (
floatval($bid) < $next_bid)

it shows
float(0.29)
float(0.29)
but the if statement still returns as true
« Last Edit: February 25, 2010, 09:00:25 AM by Renlok »

Offline PFMaBiSmAd

  • Guru
  • 'Insane!'
  • *
  • Posts: 14,588
  • In Coding, Automatic means you write code to do it
    • View Profile
Re: php inequalities problem
« Reply #3 on: February 25, 2010, 09:05:42 AM »
Read the Warning at this link - http://us.php.net/float
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

Offline RenlokTopic starter

  • Enthusiast
  • Posts: 253
  • Gender: Male
    • View Profile
    • WeLink
Re: php inequalities problem
« Reply #4 on: February 25, 2010, 10:22:09 AM »
OK thanks i finally go it to work with the bccomp() function

now i have
if (bccomp($bid$next_bid2) == -1)
:)