The floatval Function
The floatval function converts the passed value
to a floating-point number (float). As a parameter,
it accepts a variable of any type. If conversion
is impossible, the function will return 0.
Syntax
phpfloatval(mixed $value);
Example
Convert a string with a number to float:
php<?php
$res = floatval('12.34');
var_dump($res);
?>
Code execution result:
php12.34
Example
Let's try to convert a string with text:
php<?php
$res = floatval('hello');
var_dump($res);
?>
Code execution result:
php0
Example
Convert an integer to float:
php<?php
$res = floatval(123);
var_dump($res);
?>
Code execution result:
php123