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

Use the method

variablename.toFixed(2)

in your statement placing the value in the field (Where 'variablename' is, put the name of your variable).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.