Jump to content

Why 0.01 shows as 0? help


ivytony

Recommended Posts

I'm a newb in PHP.

<?php

$rate = 0.01;

$rate = ($rate * 100). "%";

echo rate;

 

?>

 

I got this result from this above code: 0%

 

I also tried to do casting by $rate = ( double ) $rate; but I still get the same result. I am wondering how to get correct value.

 

thanks!!

 

Link to comment
Share on other sites

You might want to through the bc manuals on the php.net website, i think it might be like bcmul() or something.

 

should work something like this:

<?php

echo bcmul('100', '0.01', 3); // should return 1, the three will let it go to 3 decimal places

?>

Link to comment
Share on other sites

thanks for the replies.

 

When I use $rate = 0.01 for an if statement, I got false results. For example

 

$rate = 0.01;

 

if ($rate > 0) {

do A;

}

else {

do B

}

 

The running result for this if statement is: do B. But my $rate is 0.01 which is greater than 0, right??

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.