Answer the question
In order to leave comments, you need to log in
How to round a number in javascript?
It is necessary that all non-integer numbers be rounded up to 0.5, that is, let's say I get the number 2, it remains two, if I get the number 2.1 or 2.7, then the number should be converted to 2.5, how to do this?
Answer the question
In order to leave comments, you need to log in
it is possible like this:
function round(x) {
var t = Math.floor(x);
return (t === x) ? t : t + 0.5;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question