Home  >  Article  >  Backend Development  >  Detailed explanation of the usage of php floatval() function

Detailed explanation of the usage of php floatval() function

藏色散人
藏色散人Original
2019-04-13 17:32:5514943browse

This article mainly introduces the usage of php floatval() function. I hope it will be helpful to friends in need!

floatval() function is a built-in function in PHP that returns the floating point value of a variable.

Syntax:

float floatval ( $var )

Parameters:

This function accepts one required parameter, as described below:

$var: will return its corresponding floating point value Variables. This variable should not be an object.

Return value: Returns the floating point value of the given variable. Returns 0 for an empty array and 1 for a non-empty array.

Note: If an object is passed to a function, an E_NOTICE level error is raised and 1 is returned.

floatval() function usage code example 1:

<?php 
$var = &#39;41.68127E3&#39;; 
$float_value = floatval($var); 
echo $float_value; 
?>

Output:

41681.27

floatval() function usage code example 2:

<?php 
$var = &#39;47.129mln&#39;; 
$float_value = floatval($var); 
echo $float_value; 
?>

Output:

47.129

Related recommendations: "PHP Tutorial"

The above is the detailed content of Detailed explanation of the usage of php floatval() function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn