php int to float code example
Example 1: convert a value to a float in php
$stringVal = "12.06";
$stringConvertedToFloat = floatval( $stringVal );
Example 2: php float to number format 2
<?php
$number=100000;
echo number_format($number).'<br>';
echo number_format($number, 2).'<br>';
echo number_format($number, 3).'<br>';
echo number_format($number, 2, ',', '.');
?>
Example 3: 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 4: PHP Numbers
<?php
$x = 5985;
var_dump(is_int($x));
$x = 59.85;
var_dump(is_int($x));
?>
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 = number_format($mystring, 4);
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);
?>