0

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

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by MidiMagic
0

Use the method

variablename.toFixed(2)

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

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.