lundi 2 décembre 2019

Check if an Integer is a whole Number using Javascript

Below is my code block, when I run this it is still returning values with a decimal place. Such as 15 / 2 = 7.5, instead of 8 which it should do. Does anyone know what I am doing wrong? Any help would be much appreciated.

answer = x /y;

if (Number.isInteger(answer) == false) {
        Math.round(answer);
        return answer;
    }
else return answer;
}



Aucun commentaire:

Enregistrer un commentaire