How can I round to whole numbers in JavaScript? How can I round to whole numbers in JavaScript? javascript javascript

How can I round to whole numbers in JavaScript?


Use the Math.round() function to round the result to the nearest integer.


//method 1Math.ceil(); // rounds upMath.floor(); // rounds downMath.round(); // does method 2 in 1 call//method 2var number = 1.5; //floatvar a = parseInt(number); // to intnumber -= a; // get numbers on right of decimalif(number < 0.5) // if less than round down    round_down();else // round up if more than    round_up();

either one or a combination will solve your question


total = Math.round(total);

Should do it.