Forums
This topic is locked
i need help making decimals always show up
Posted 13 Nov 2007 20:27:59
1
has voted
13 Nov 2007 20:27:59 jessica wallis posted:
I have a page where three funds add up to a total and need it to have decimals, but don't know how to get it to.I need the total to have decimals in the amount field in the form so it will properly pass to the processing website. it adds decimals but they only show up in the total if there is something other than .00. i need the decimals to show up in the total regardless of whether the person entering values into the first 3 fields uses decimals or not.
Here is the javascript:
<script language="javascript">
function getTotal()
{
var merchant_defined_field_11, merchant_defined_field_12, merchant_defined_field_13, total;
if(document.fund.merchant_defined_field_11.value == '') { merchant_defined_field_11 = 0.00; } else { merchant_defined_field_11 = parseFloat(document.fund.merchant_defined_field_11.value); }
if(document.fund.merchant_defined_field_12.value == '') { merchant_defined_field_12 = 0.00; } else { merchant_defined_field_12 = parseFloat(document.fund.merchant_defined_field_12.value); }
if(document.fund.merchant_defined_field_13.value == '') { merchant_defined_field_13 = 0.00; } else { merchant_defined_field_13 = parseFloat(document.fund.merchant_defined_field_13.value); }
var total = merchant_defined_field_11 + merchant_defined_field_12 + merchant_defined_field_13;
if(!parseFloat(total))
{
document.fund.total.value = "Please enter a number";
}
else
{
document.fund.total.value = total;
}
}
</script>
ANY HELP WOULD BE GREATLY APPRECIATED
Replies
Replied 27 Nov 2007 13:09:54
27 Nov 2007 13:09:54 Seb Adlington replied:
Hi Jessica,
try this, a basic one but works most of the time
total = total.toFixed(2);
I've sometimes had random errors with this - let me know
Cheers
Seb
try this, a basic one but works most of the time
total = total.toFixed(2);
I've sometimes had random errors with this - let me know
Cheers
Seb