What does float mean in javascript

青灯夜游
Release: 2022-09-20 16:28:05
Original
2643 people have browsed it

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;" .

What does float mean in javascript

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;
Copy after login

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;
Copy after login

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>
Copy after login

After the program runs, the console output is as follows:

What does float mean in javascript

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>
Copy after login

After the program is run, the console output is as follows:

What does float mean in javascript

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!

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