PHP float with 2 decimal places: .00

后端 未结 11 1063
野性不改
野性不改 2020-12-08 06:34

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?

11条回答
  •  忘掉有多难
    2020-12-08 06:56

    A float isn't have 0 or 0.00 : those are different string representations of the internal (IEEE754) binary format but the float is the same.

    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);
    

提交回复
热议问题