Hello.

How to get float (10.00) from int (10)?

Options with the addition of $string .= ".00"; not interested.

    1 answer 1

    You can cast a variable to a float / double type using one of the methods of explicit type casting.

     <?php $number = (double)10; echo gettype($number); 

    or so

     <?php $number = 10; settype($number, 'float'); echo gettype($number); 

    If you are interested in formatting, you can use the function sprintf()

     <?php echo sprintf('%0.2f', 10); 

    or printf()

     <?php printf('%0.2f', 10); 
    • everything is exactly the result of 10, not 10.00 - ikerya
    • 3
      @ikeria, can try round ((float) 10, 2); - DanielOlivo 4:38 pm
    • @ikerya, corrected the answer - cheops
    • one
      @ikerya, the DanielOlivo version is also quite a worker, did not have time to bring it :) - cheops
    • 3
      Все забыли про number_format :( (c) modal - ikerya pm