PHP floatval() Function

PHP floatval() Function

The floatval() function in PHP is used to give the float value of a variable.

Syntax

floatval ( mixed $var )

Parameter

var(required)- This parameter represents the name of the variable that is to be converted.

Return

This function returns the float value of the given variable.

If the var is initialized with empty arrays, it returns 0 else for non-empty arrays it returns 1. The strings will most likely return 0 although this depends on the leftmost characters of the string.

Example 1

 

Output

The variable: 417.209mln
After the floatval() function
New Variable: 417.209 

Example 2

 

Output

The variable: The417.209mln
After the floatval() function
New Variable: 0 

Example 3

 

Output

The variable: 
After the floatval() function
New Variable: 0 

Example 4

 

Output

The variable: !@#$%
After the floatval() function
New Variable: 0 

Example 5

 

Output

The variable: 123.00000001
After the floatval() function
New Variable: 123.00000001