js isinteger_在JavaScript中使用示例使用Number isInteger()方法

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值