StackOverflowNewbie StackOverflowNewbie - 1 year ago 98
PHP Question

PHP float with 2 decimal places: .00

When I do this typecasting:

(float) '0.00';

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

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download