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

Does javascript distinguish between integers and floating point numbers?

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-07-16 10:39:132875browse

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>

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!

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