Round To Cents

[Total: 0    Average: 0/5]

This shows how to use math.round as well as parseInt to yeild money values.

Body Code:

<script>
var _start=Math.random()*1000; /* just get a number to start this off with */
document.write("START="+_start+"<BR>");

var _end1=Math.round(_start);
document.write("Math.round("+_start+")="+_end1+"<BR>");

var _end2=parseInt(_start);
document.write("parseInt("+_start+")="+_end2+"<BR>");

var _end3=Math.round(_start*100)/100;
document.write("Math.round("+_start+"*100)/100="+_end3+"<BR>");

var _end4=parseInt(_start*100)/100;
document.write("parseInt("+_start+"*100)/100="+_end4+"<BR>");

</script>

Times Viewed: 9

Leave a Reply

Your email address will not be published. Required fields are marked *