Jump to content

comparing numbers


ksmatthews

Recommended Posts

HI all,

 

I would like to know how to correctly compare numbers.

 

For example, I have 2 vars $x and $y that both contain varchars from a DB dump.

 

If $x = 9 and $y = 10, obviously $x < $y BUT when I compare them it seems to suggest the $x > $y

 

How can I convert them into INTS or indeed FLOATS, if I needed them ? I always thought that this was automatic in PHP.

It certainly is NOT in the C language where you would need to use atoi().

 

regards,

 

Steven M

Link to comment
https://forums.phpfreaks.com/topic/119950-comparing-numbers/
Share on other sites

from my days as a maths student, you need to bring them down to a common denominator. I suppose it may be that i just have no idea what you're trying to do, but they both need to be playing with the same format.

 

if you want a float, you can use something like number_format($number, 2) That then sets it to 2 decimal places.

 

is that what you're after?

Link to comment
https://forums.phpfreaks.com/topic/119950-comparing-numbers/#findComment-617995
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.