Emperor01 / JSlearn

all my practical trainings
0 stars 0 forks source link

don't work with numbers less than -1 #1

Closed Emperor01 closed 6 years ago

Emperor01 commented 6 years ago

function getDecimal () { var num = prompt('input number',''); var decimal; if (num > 0) { decimal = num - Math.floor(num); } else { decimal = num + Math.ceil(num); } decimal = Math.round(decimal * 1000) / 1000; return decimal; }

alert(getDecimal());

Emperor01 commented 6 years ago

added + before prompt and now if I input -2.4 I have -4.4

Emperor01 commented 6 years ago

problem has been decided

Emperor01 commented 6 years ago

xD

Emperor01 commented 6 years ago

function getDecimal () { var num = +prompt('input number',''); var decimal; if (num > 0) { decimal = num - Math.floor(num); } else { decimal = num - Math.ceil(num); } decimal = Math.round(decimal * 1000) / 1000; return decimal; }

alert(getDecimal());