Jump to content

Comparing Value


Alicia

Recommended Posts

Hi,

 

May I know why my conditional statement doesn't work when comparing with decimal point input?

 

$money = 0.2;

 

if($money<=0)

{

echo 'no money';

{

else

{

echo 'OK';

}

 

The output after multiple tries by using intval or float , it still show OK when it suppsed to show no money...

 

May i know what I have missed? it seems like the php script cant recognize 0.2 is smaller than 0.

 

please advise

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

Hi,

 

May I know why my conditional statement doesn't work when comparing with decimal point input?

 

$money = 0.2;

 

if($money<=0)

{

echo 'no money';

{

else

{

echo 'OK';

}

 

The output after multiple tries by using intval or float , it still show OK when it suppsed to show no money...

 

May i know what I have missed? it seems like the php script cant recognize 0.2 is smaller than 0.

 

please advise

 

change your code into

 

$money = 0.2;

 

if($money<=1)

{

echo 'no money';

}

else

{

echo 'OK';

}

 

0.2 is greater than zero

 

hope it works :D

Link to comment
https://forums.phpfreaks.com/topic/269636-comparing-value/#findComment-1386189
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.