topical media & game development
basic-javascript-04-ch4-examp4.htm / htm
<html>
<head>
<script language="JavaScript" type="text/javascript">
function fix(fixNumber, decimalPlaces)
{
var div = Math.pow(10,decimalPlaces);
fixNumber = Math.round(fixNumber * div) / div;
return fixNumber;
}
</script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
var number1 = prompt("Enter the number with decimal places you want to fix","");
var number2 = prompt("How many decimal places do you want?","");
document.write(number1 + " fixed to " + number2 + " decimal places is: ");
document.write(fix(number1,number2));
</script>
</body>
</html>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.