I am trying to round my figure in JavaScript if it is less then any 0.5 figure. For Instance if I have value 3.4 then it should be 3 but if 3.5 then there is no need to round figure. I only want to round figure if it is less than 0.5. Here is the code I am using to round figure. But it rounded the figure in both cases
This code gives me result 3.5
function rounded(){
var val = 3.5;
var rounded = Math.round(val);
console.log("rounded",rounded);
}
and this code gives me result 4 but I want 3.5..
function rounded(){
var val = 3.6;
var rounded = Math.round(val);
console.log("rounded",rounded);
}
Any body can help me with this?