Friday, October 24, 2025
HomeLanguagesPHP | floatval() Function

PHP | floatval() Function

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;
?>


Output:

41681.27

Program 2:




<?php
$var = '47.129mln';
$float_value = floatval($var);
echo $float_value;
?>


Output:

47.129

Reference: http://php.net/manual/en/function.floatval.php

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS