$floatValue = floatval("1.0");
method_1:
intval($string);//for string to integer
floatval($string); //for string to float
method_2:
$int = (int)$string;//string to int
$float = (float)$string;//string to float
phpCopy<?php
$mystring = "0.5674";
echo("This float number is of string data type ");
echo($mystring);
echo("
");
$myfloat = floatval($mystring);
echo("Now, this float number is of float data type ");
echo($myfloat);
?>
phpCopy<?php
$mystring = "0.5674";
echo("This float number is of string data type ");
echo($mystring);
echo("
");
$myfloat = number_format($mystring, 4);
echo("Now, this float number is of float data type ");
echo($myfloat);
?>
phpCopy<?php
$mystring = "0.5674";
echo("This float number is of string data type ");
echo($mystring);
echo("
");
$myfloat = (float) $mystring;
echo("Now, this float number is of float data type ");
echo($myfloat);
?>
$num = '1,200,998.255';
########## FOR FLOAT VALUES ###########################
echo filter_var($num, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
#output : 1200998.255
########## FOR INTEGER VALUES ###########################
echo filter_var($num, FILTER_SANITIZE_NUMBER_INT);
#output : 1200998
// floatval() function to convert
// string to float
echo floatval($num);
parseFloat( num.toFixed(2) )
<?php
$num = 109;
$numf = sprintf("%.2f",$num);
echo $numf;
?>