PHP float with 2 decimal places: .00

后端 未结 11 1062
野性不改
野性不改 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 07:06

    When we format any float value, that means we are changing its data type to string. So when we apply the formatting on any amount/float value then it will set with all possible notations like dot, comma, etc. For example

    (float)0.00 => (string)'0.00',
    (float)10000.56 => (string) '10,000.56'
    (float)5000000.20=> (string) '5,000,000.20'
    

    So, logically it's not possible to keep the float datatype after formatting.

提交回复
热议问题