Home > Web Front-end > JS Tutorial > Does javascript distinguish between integers and floating point numbers?

Does javascript distinguish between integers and floating point numbers?

醉折花枝作酒筹
Release: 2023-01-07 11:43:42
Original
2899 people have browsed it

JavaScript does not distinguish between integer values ​​and floating point values. Number types can be stored. If you pass a string to the Number() conversion function, it attempts to convert it to an integer or floating point number.

Does javascript distinguish between integers and floating point numbers?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

JavaScript does not distinguish between integer values ​​and floating point values. Number types can be stored.

If you pass a string to the Number() conversion function, it attempts to convert it into an integer or floating point number.

JavaScript Numeric

JavaScript has only one numeric type.

You can use or not use decimal points when writing values:

Example:

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript 数值</h2>

<p>写数值时用不用小数点均可:</p>

<p id="demo"></p>

<script>
var x1 = 34.00;
var x2 = 34;
var x3 = 3.14;

document.getElementById("demo").innerHTML =
x1 + "<br>" + x2 + "<br>" + x3;
</script>

</body>
</html>
Copy after login

Result:

Does javascript distinguish between integers and floating point numbers?

##[Recommended learning :

javascript advanced tutorial

The above is the detailed content of Does javascript distinguish between integers and floating point numbers?. 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