Method 1: Using number_format() Function. The number_format() function is used to convert string into a number. It returns the formatted number on success otherwise it gives E_WARNING on failure.
Example:1
<?php
$num="1000.314";
//convert a string in number using
//number format function
echo number_format($num),"\n";
//convert string in number using
//number format function
echo number_format($num,2);
?>
<?php
//number is string fromat
$num="1000.314";
//type cast using int
echo (int)$num,"\n";
//type cast is using float
echo (float)$num,"\n";
//type cast using double
echo (double)$num,"\n";
?>
<?php
// Number in string format
$num = "1000.314";
// intval() function to convert
// string into integer
echo intval($num), "\n";
// floatval() function to convert
// string to float
echo floatval($num);
?>
<?php
$num="1000.314";
//perfomrming mathematical operation
//to implicity type conversion
echo $num+0, "\n";
//performing mathematical operation
//to implicity type conversion
echo $num+0.0,"\n";
//performing mathematical operation
//to implicity type ocnversion
echo $num+0.1 ;
?>