Jump to content

Comparing Floats and Strings


random1

Recommended Posts

Hi All,

 

How do you compare floats in PHP?

 

I am comparing browser versions and need to know how compare the following:

 

$browserversion = "2.0.0.14"; // Firefox version

$supportedversion = "2.0.0.00" // Minimum supported version of Firefox

 

if($browserversion >= "2.0.0.00")

{

echo("Browser is supported");

}

else

{

echo("Browser is not supported");

}

 

I also need comparisons for Safari and Opera:

 

e.g. if ($operaversion >= 9.0){echo("Opera version is supported...");}

Link to comment
https://forums.phpfreaks.com/topic/104128-comparing-floats-and-strings/
Share on other sites

<?php
$browserversion = "2.0.0.14"; // Firefox version
$supportedversion = "2.0.0.00"; // Minimum supported version of Firefox

if($browserversion >= $supportedversion)
{
    echo "Browser is supported";
}
else
{
    echo "Browser is not supported";
}
?>
gives--> Browser is supported

 

So your problem is what exactly?

Not on my server

<?php
$browserversion = "2.0.0.14"; // Firefox version
$supportedversion = "2.0.0.15"; // Minimum supported version of Firefox

if($browserversion >= $supportedversion)
{
    echo "Browser is supported";
}
else
{
    echo "Browser is not supported";
}
?>

--> Browser is not supported

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.