function f(num, zeros) { var factor = +("1e" + zeros); return Math.round(num *factor) /factor; }; f(123.124252,2) //123.12 f(123.125252,2) //123.13