Home  >  Article  >  Web Front-end  >  How to use Number function

How to use Number function

不言
不言Original
2019-02-20 17:51:405195browse

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)

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>

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>

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>

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!

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
Previous article:How to use join methodNext article:How to use join method