如何创建if语句以检查整数是否以0结尾?
例如,我希望有这样一个if-语句:
var test = 107; //107 is an example it'should some unknown number
if(test is xx1 - xx9){
//do something
}
else if(test is xx0){
//do something
}发布于 2016-05-09 03:15:51
var test=107;
var isEndsWithZero =test%10;
if(isEndsWithZero!==0)
{
//Ends With 1-9,Do something
alert("Ends With 1 to 9");
}
else
{
//Ends With Zero ,Do something
alert ("ends with zero");
}示例:
test=107;
isEndsWithZero=107%10 //7
Else part will get executedJSFiddle链接:https://jsfiddle.net/nfzuaa44/
发布于 2016-05-09 03:14:07
if (test % 10) {
// does not end with 0
} else {
// ends with 0
}发布于 2016-05-09 03:14:50
if(/0$/.test(number)) {
/* it ends in a 0 */
}
else {
/* it doesn't */
}https://stackoverflow.com/questions/37107240
复制相似问题