<返回更多

JS中判断一个数是否是浮点数的两个方法

2022-05-13    jsob2
加入收藏

方法一:

if(value.toString().indexOf(".") != -1){
//是浮点数
return;
}

方法二:

if(parseInt(value, 10) != value){
//是浮点数
return;
}

例程:

var value=123.1
if(value.toString().indexOf(".") != -1){
console.log(value,"是浮点数");
}
if(parseInt(value, 10) != value){
console.log(value,"是浮点数");
} 

例程运行效果:

JS中判断一个数是否是浮点数的两个方法

 

不想让他人知道是怎么判断的?用JShaman对例程代码加密,得到加密JS代码:

var _0xef23=['toString','indexOf','log','是浮点数'];var _0x2e81=function(_0xef2387,_0x2e818f){_0xef2387=_0xef2387-0x0;var _0x19decf=_0xef23[_0xef2387];return _0x19decf;};var _0xe1937a=function(_0x244967,_0x340dfc,_0x1bb7fb,_0x307ae3,_0x4df4f1){return _0x2e81(_0x307ae3-0x36e,_0x4df4f1);};var _0x3f05b2=function(_0xa449a5,_0x2726b1,_0x4cf069,_0x5de6f1,_0x178b9c){return _0x2e81(_0x5de6f1-0x36e,_0x178b9c);};var _0x3014a7=function(_0x4a877f,_0x4dfe5f,_0x5f2bcb,_0x3331e4,_0x594f3f){return _0x2e81(_0x3331e4-0x36e,_0x594f3f);};var _0x43c3a=function(_0x4cf669,_0x187059,_0x27a593,_0xce2b84,_0x3ba0ac){return _0x2e81(_0xce2b84-0x36e,_0x3ba0ac);};var _0x2a9d2d=function(_0xaa5df2,_0x35ebec,_0x598ec2,_0x524706,_0x44eefd){return _0x2e81(_0x524706-0x36e,_0x44eefd);};var value=123.1;if(value[_0xe1937a(0x36d,0x36d,0x36e,0x36e,0x36f)]()[_0x3f05b2(0x36f,0x371,0x371,0x36f,0x371)]('.')!=-(0xf13f0^0xf13f1)){console[_0x3f05b2(0x36e,0x370,0x371,0x370,0x371)](value,_0xe1937a(0x373,0x370,0x371,0x371,0x36f));}if(parseInt(value,0xf4169^0xf4163)!=value){console[_0x2a9d2d(0x36e,0x372,0x36f,0x370,0x36e)](value,_0x3014a7(0x370,0x36f,0x371,0x371,0x371));}

加密后代码的运行效果:

JS中判断一个数是否是浮点数的两个方法

 

声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>