The floatval() function is an inbuilt function in PHP which returns the float value of a variable.
Syntax:
float floatval ( $var )
Parameters: This function accepts one parameter which is mandatory and described below:
- $var: The variable whose corresponding float value will be returned. This variable should not be an object.
Return Value: It returns float value of given variable. Empty array returns 0 and non-empty array returns 1.
Note: If an object is passed to the function, it produce an E_NOTICE level error and return 1.
Examples:
Input : $var = '41.68127E3' Output : 41681.27 Input : $var = '47.129mln' Output : 47.129
Below programs illustrate the use of floatval() function in PHP:
Program 1:
<?php $var = '41.68127E3'; $float_value = floatval($var); echo $float_value; ?> |
41681.27
Program 2:
<?php $var = '47.129mln'; $float_value = floatval($var); echo $float_value; ?> |
47.129
Reference: http://php.net/manual/en/function.floatval.php
Recommended Posts:
- How to Check a Function is a Generator Function or not using JavaScript ?
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- How to get the function name inside a function in PHP ?
- PHP | end() Function
- D3.js zip() Function
- p5.js | log() function
- CSS env() Function
- p5.js | int() function
- CSS | var() Function
- p5.js | str() function
- PHP | ord() Function
- p5.js | sin() function
- p5.js | tan() function
- p5.js | max() function
- p5.js | arc() Function
- p5.js | sq() function
- PHP | each() Function
- p5.js | pow() function
- p5.js | second() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

