Home > Web Front-end > JS Tutorial > body text

How to use Number function

不言
Release: 2019-02-20 17:51:40
Original
5210 people have browsed it

Number() in How to use Number function is a built-in javascript function used to convert data types to numbers. Let's take a look at the specific use of the Number function.

How to use Number function

Let’s first take a look at the basic syntax of the Number function

Number(query javascript variable)
Copy after login

Parameters: The number function is the javascript variable input by the user to be converted. The number function converts any type of javascript variable to numeric type.

The number function returns the number format of any type of javascript variable.

Let’s look at a few specific examples

Example 1:

The code is as follows

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
<script> 
function func() { 
  
        var value = Number(true); 
        document.write(value); 
    } 
func(); 
</script>  
</body>
</html>
Copy after login

The output result is: 1

Example 2:

The code is as follows

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
<script> 
 function func() { 
        var a = "10 20"; 
  
        var value = Number(a); 
        document.write(value); 
    } 
func(); 
</script>  
</body>
</html>
Copy after login

The output result is: NaN

Example 3:

The code is as follows

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
<script> 
function func() { 
        var value = Number(new Date("2017-09-30")); 
        document.write(value); 
    } 
func(); 
</script>  
</body>
</html>
Copy after login

The output result is: 1506729600000

This article ends here. For more exciting content, you can pay attention to other related column tutorials on the PHP Chinese website! ! !

The above is the detailed content of How to use Number function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template