function roundit(what,places,iplaces,pad) { var xx = what.indexOf('.') var l = what.length var zstr = '0000000000000000000000' var theInt = '' var theFrac = '' var theNo = '' rfac = '' rfacx = 0 whatx = 0 var xt = parseInt(places) + 1 var rstr = '' + zstr.substring(1,xt) var rfac = '.' + rstr + '5' var rfacx = parseFloat(rfac) if (xx == -1 ) { alert('No fraction') theFrac = zstr theInt = what.substring(1,xx) } else if (xx == 0) { theInt = '0' whatx = 0 + parseFloat(what) + parseFloat(rfacx) what = whatx + zstr theFrac = '' + what.substring(1, what.length) } else { theInt = what.substring(0,xx) whatx = parseFloat(what) + rfacx what = '' + whatx + zstr theFrac = '' + what.substring(xx+1,xx + 1 + parseInt(places)) var astr = 'places = ' + places } //alert('theInt= ' + theInt + '\ntheFrac= ' + theFrac + '\nwhat= ' + what + '\nwhatx= ' + whatx) theFrac = theFrac.substring(0,parseInt(places)) var dif = iplaces - theInt.length var ii = 0 var padstr = '' for (ii = 0 ; ii < dif ; ii++) { padstr += pad } theNo = padstr + theInt + '.' + theFrac return theNo }