w3resource

php.js: floatval() function

floatval() function

The floatval() function is used to get the float value of a variable.

Version:

1103.1210

Syntax:

floatval (var1)

Parameters:

Name Description Required /
Optional
Type
var1 The variable to get float value. Required Mixed*

*Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types.

Example of php.js floatval() function:

In the following web document floatval() function is used to get the float value of a variable.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>php.js : floatval() function example</title>
<script type="text/javascript" src="../../phpjs/variable/variable.min.js"> </script>
</head>
<body>
<h1 style="color: green">php.js : floatval() function example</h1>
<h3>Float value of a variable.</h3>
<hr />
<script type="text/javascript">
//This is done to make the following JavaScript code compatible to XHTML. <![CDATA[
var_name1="122.00,50";
var_name2="122.00";
var_name3="122.50";
var_name4="122,50";
var_name5="122 50";
var_name6="0.50";
var_name7="0,50";
var_name8="-122.50";
var_name9="-122,50";
var_name10="-122 50";
document.write(floatval(var_name1)+"<br>");
document.write(floatval(var_name2)+"<br>");
document.write(floatval(var_name3)+"<br>");
document.write(floatval(var_name4)+"<br>");
document.write(floatval(var_name5)+"<br>");
document.write(floatval(var_name6)+"<br>");
document.write(floatval(var_name7)+"<br>");
document.write(floatval(var_name8)+"<br>");
document.write(floatval(var_name9)+"<br>");
document.write(floatval(var_name10)+"<br>");
//]]>
</script>
</body>
</html>

Output of the function:

122
122
122.5
122
122
0.5
0
-122.5
-122
-122

View example of php.js floatval() function in browser

Download phpjs.zip

Previous: php.js : empty() function
Next: php.js : get_defined_vars() function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/phpjs/variable/floatval.php