js isinteger
编号isInteger()方法 (Number isInteger() Method)
isInteger() is a Number Method, it is used to check whether a given number is an integer or not.
isInteger()是一个数字方法,用于检查给定数字是否为整数。
It returns true if given number is an integer, if given number is not an integer – it returns false.
如果给定数字是整数,则返回true;如果给定数字不是整数,则返回–返回false 。
Syntax:
句法:
Number.isInteger(number);
Examples:
例子:
Input: 10
Output: true
Input: 10.23
Output: false
Input: "Hello"
Output: False
Code:
码:
<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
document.write("10: " + Number.isInteger(10) + "<br>");
document.write("10.23: " + Number.isInteger(10.23) + "<br>");
document.write("Hello: " + Number.isInteger("Hello") + "<br>");
//checking with variables
var a = 10;
var b = 10.23;
var c = "Hello";
if(Number.isInteger(a)==true)
document.write(a + " is an integer value" + "<br>");
else
document.write(a + " is not an integer value" + "<br>");
if(Number.isInteger(b)==true)
document.write(b + " is an integer value" + "<br>");
else
document.write(b + " is not an integer value" + "<br>");
if(Number.isInteger(c)==true)
document.write(c + " is an integer value" + "<br>");
else
document.write(c + " is not an integer value" + "<br>");
</script>
</body>
</html>
Output
输出量
10: true
10.23: false
Hello: false
10 is an integer value
10.23 is not an integer value
Hello is not an integer value
翻译自: https://www.includehelp.com/code-snippets/number-isInteger-method-with-example-in-javascript.aspx
js isinteger