StackOverflowNewbie StackOverflowNewbie - 5 months ago 22
PHP Question

PHP float with 2 decimal places: .00

When I do this typecasting:

(float) '0.00';


I get
0
. How do I get
0.00
and still have the data type as a float?

Answer

You don't have 0 or 0.00 : those are different representations of the internal (IEEE754) binary format.

If you want to express your float as "0.00", you need to format it in a string, using number_format :

$numberAsString = number_format($numberAsFloat, 2);
Comments