php string to float code example
Example 1: php string to uppwe
$lowercase = "this is lower case";
$uppercase = strtoupper($lowercase);
echo $uppercase;
Example 2: convert a value to a float in php
$stringVal = "12.06";
$stringConvertedToFloat = floatval( $stringVal );
Example 3: string to float php
$floatValue = floatval("1.0");
Example 4: php float value
floatval ($var)
Example 5: 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 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 = floatval($mystring);
echo("Now, this float number is of float data type ");
echo($myfloat);
?>