Suppose I have a value of 15.7784514, I want to display it 15.77 with no rounding.
var num = parseFloat(15.7784514); document.write(num.toFixed(1)+\"
My version for positive numbers:
function toFixed_norounding(n,p) { var result = n.toFixed(p); return result <= n ? result: (result - Math.pow(0.1,p)).toFixed(p); }
Fast, pretty, obvious. (version for positive numbers)