php convert string to float code example
Example 1: convert a value to a float in php
$stringVal = "12.06";
$stringConvertedToFloat = floatval( $stringVal );
Example 2: string to float php
$floatValue = floatval("1.0");
Example 3: php float value
floatval ($var)
Example 4: number format to float php
$num = '1,200,998.255';
echo filter_var($num, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
echo filter_var($num, FILTER_SANITIZE_NUMBER_INT);
Example 5: Convert String to Float in PHP
phpCopy<?php
$mystring = "0.5674";
echo("This float number is of string data type ");
echo($mystring);
echo("\n");
$myfloat = floatval($mystring);
echo("Now, this float number is of float data type ");
echo($myfloat);
?>
Example 6: Convert String to Float in PHP
phpCopy<?php
$mystring = "0.5674";
echo("This float number is of string data type ");
echo($mystring);
echo("\n");
$myfloat = (float) $mystring;
echo("Now, this float number is of float data type ");
echo($myfloat);
?>