I have some code that tell what currency (dollars, quarters, dimes, nickels, and pennies) to dispence based on an input number. Everything works fine except the calculation itself. It give the correct dollars, quarters, and dimes, but does not alway give the correct nickels and pennies. Here is the code I have:
<script type=”text/javascript”>
<!–
function evaluate (amt) {
amt.value = amt.value.match(/[d.
amt.form.dollars.value = Math.floor(amt.value / 1);
amt.form.quarters.value = Math.floor((amt.value % 1) / .25);
amt.form.dimes.value = Math.floor((amt.value % .25) / .10);
amt.form.nickles.value = Math.floor((amt.value % .10) / .05);
amt.form.pennies.value = Math.floor((amt.value % .05) / .01);
}
// –>
</script>
<form action=””>
<div>
<label>Amount<br><input name=”amount” type=”text” onchange=”evaluate(this)”></label>
<label>Dollars<br><input name=”dollars” type=”text”></label>
<label>Quarters<br><input name=”quarters” type=”text”></label>
<label>Dimes<br><input name=”dimes” type=”text”></label>
<label>Nickles<br><input name=”nickles” type=”text”></label>
<label>Pennies<br><input name=”pennies” type=”text”></label>
</form>
Thanks for your help in advance. I appreciate it.