Can anyone take a look at the following code and tell me how to get it to display the decimal place?
[code]
<!– hide this script tag’s contents from old browsers
function round2d(n)
{
return(Math.floor(100*n)/100);
}
function checkNumber(input, min, max, msg)
{
msg = msg + ” field has invalid data: ” + input.value;
var str = input.value;
for (var i = 0; i < str.length; i++) {
var ch = str.substring(i, i + 1)
if ((ch < “0” || “9” < ch) && ch != ‘.’) {
alert(msg);
return false;
}
}
var num = 0 + str
if (num < min || max < num) {
alert(msg + ” not in range [” + min + “..” + max + “]”);
return false;
}
input.value = str;
return true;
}
function computeField(input)
{
if (input.value != null && input.value.length != 0)
input.value = “” + eval(input.value);
computeForm(input.form);
}
function computeForm(form)
{
if ((form.hours_complete.value == null || form.hours_complete.value.length == 0)) {
return;
}
if (!checkNumber(form.hours_complete, .5, 120, “Hours”)) {
form.gradepoints.value = “Invalid”;
return;
}
if ((form.hours_attempt.value == null || form.hours_attempt.value.length == 0)) {
return;
}
form.rate.value = (round2d(form.hours_complete.value / form.hours_attempt.value) * 100);
}
function clearForm(form)
{
form.hours_complete.value = “”;
form.rate.value = “”;
form.hours_attempt.value = “”;
}
//–>
</script>
Edited by site staff: Inserted code tags.