Home > Article > Web Front-end > What does float mean in javascript
In JavaScript, float means "floating point number" and is represented by Number objects. JavaScript's floating point numbers have two forms of expression: 1. Use ordinary decimal representation, such as "num = 1024.112;"; 2. Use scientific notation, such as "num1 = 1024e3;" or "num2 = 1024e-3;" .
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In JavaScript, float refers to "floating point number".
Numbers in JavaScript can be divided into integer and floating-point number types. JavaScript’s floating-point numbers are represented by Number objects. There are two forms of representation of floating point numbers in JavaScript. The first is to use ordinary decimal representation, and the second is to use scientific notation.
Declaring JavaScript floating point numbers
Syntax
var num = 1024.112;
Description
We use the var keyword to declare a floating point variable, num, whose value is 1024.112.
Declaring JavaScript floating point numbers
Syntax
var num1 = 1024e3; var num2 = 1024e-3;
Description
We use the var keyword to declare two floating point variables, namely num1 and num2, whose values are 1024 times 10 to the third power and 1024 times 10 to the -3 power respectively.
JavaScript The scientific notation representation of floating point numbers is to use e as the base, followed by a number, which means multiplying by 10 to the Nth power.
Case
#Define a floating point number
Define a JavaScript floating point number and print
<!DOCTYPE html> <html> <head> <title>JavaScript浮点数</title> <script type="text/javascript"> var fnum = 1014.1024; console.log("fnum =", fnum); var fnum2 = -1024.1024; console.log("fnum2 =", fnum2); </script> </head> </html>
After the program runs, the console output is as follows:
We first use the var keyword to declare a floating point variable fnum and assign it a value of 1024.1024 , and print its content. Then, we define a floating point variable fnum2 again, assign it a value of -1024.1024, and print it.
Scientific notation defines floating point numbers
Uses scientific notation to define floating point numbers
<!DOCTYPE html> <html> <head> <title>使用科学计数法定义浮点数</title> <script type="text/javascript"> var fnum = 1024e2; console.log("fnum =", fnum); var fnum2 = 1024e-2; console.log("fnum2 =", fnum2); </script> </head> </html>
After the program is run, the console output is as follows:
We first use the var keyword to declare a floating point number fnum using scientific notation, and assign it a value of 1024e2, which is 1024 times the square of 10. Then, we A floating point number fnum2 is declared again using scientific notation and assigned a value of 1024e-2, which is 1024 times 10 raised to the power of -2.
【Related recommendations: javascript video tutorial, Basic programming video】
The above is the detailed content of What does float mean in javascript. For more information, please follow other related articles on the PHP Chinese website!