Alternative for Math.round() Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Alternative for Math.round() without wasting too much if your time.

The question is published on by Tutorial Guruji team.

In JavaScript when value is 4.3, i want it to round off to 4 and if value is 4.5 or above it rounds off to 5. I want all this without using Math.round().

Answer

You can do this

function RoundNum(number){
    var c = number % 1;
    return number-c+(c/1+1.5>>1)*1
}

console.log(RoundNum(2.456));
console.log(RoundNum(102.6));
console.log(RoundNum(203.515));
We are here to answer your question about Alternative for Math.round() - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji