anson920520 anson920520 - 6 months ago 8
Javascript Question

If statement to identify the round up

How may i create a if statement in order to define if an integer does not end with 0?

For example i have a if statement like below

var test = 107; //107 is an example it'should some unknown number

if(test's number is xx1 - xx9){
//do something
}
else if(test's number is xx0){
//do something
}

Answer
      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");
      }

Example:

test=107;
isEndsWithZero=107%10 //7
Else part will get executed

JSFiddle Link :https://jsfiddle.net/nfzuaa44/