Javascript Math round(num, dec)
// Javascript has nice built in function to properly round a number. Here's one. var round = function (num, dec) { var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec); return result;/*from www . j ava2s. co m*/ };