isSafeInteger()
Number对象的功能接受一个数字并确定它是否为安全整数。如果给定的数字是安全整数,则返回true,否则返回false。
其语法如下
Number.isSafeInteger(90071991);
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var result = Number.isSafeInteger(90071991); if(result) { document.write("Given number is a safe integer"); }else { document.write("Given number is not a safe integer"); } </script> </body> </html>
输出结果
Given number is a safe integer
将十进制值,负值和一个方程式传递给此函数。
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var result1 = Number.isSafeInteger(45.2); document.write(result1); document.write("<br>"); var result2 = Number.isSafeInteger(-38); document.write(result2); document.write("<br>"); var result3 = Number.isSafeInteger(0/8); document.write(result3); document.write("<br>"); </script> </body> </html>
输出结果
false true true