Cast int to float, two decimal values in PHP

menislici picture menislici · Oct 21, 2012 · Viewed 43.5k times · Source

Possible Duplicate:
PHP: show a number to 2 decimal places

How do I cast an integer, let's say $i=50 to a float with two decimal values: $m=50.00? I have tried (float)$i but nothing happens.

EDIT:

I need to make $i == $m so that returns TRUE;

Answer

davepmiller picture davepmiller · Oct 21, 2012

round((float)$i, 2) Should do the trick.

The round function is built in and rounds a given float to the number of decimal places specified in the given argument.

Ahh yes, number_format($var, 2) is good as well !