PHP : Convert(cast) int to double/float



Tags : convert casting int float double php

Problem :

You have an integer value and you need to convert it ot double or float value in PHP

Solution :

Use the number_format function to cast the integer to float value. For example :

 <?php

 $integer = 2;

 echo $integer.'<br>';

 $float = number_format($integer,3); // up to 3 decimals

 echo $float.'<br>';
 ?>

  See also : PHP : Convert(cast) string to bigInt



Tags : convert casting int float double php

By Adam Ng

IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.


Advertisement