PHP float with 2 decimal places: .00

后端 未结 11 1053
野性不改
野性不改 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:08

    You can show float numbers

    • with a certain number of decimals
    • with a certain format (localised)

    i.e.

    $myNonFormatedFloat = 5678.9
    
    $myGermanNumber = number_format($myNonFormatedFloat, 2, ',', '.'); // -> 5.678,90
    
    $myAngloSaxonianNumber = number_format($myNonFormatedFloat, 2, '.', ','); // -> 5,678.90 
    

    Note that, the

    1st argument is the float number you would like to format

    2nd argument is the number of decimals

    3rd argument is the character used to visually separate the decimals

    4th argument is the character used to visually separate thousands

提交回复
热议问题