User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 363,508 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,423 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 483 | Replies: 1
Reply
Join Date: Sep 2007
Posts: 3
Reputation: Jwallis is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Jwallis Jwallis is offline Offline
Newbie Poster

Help with making decimals show up always

  #1  
Nov 13th, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Posts: 2,361
Reputation: MidiMagic is on a distinguished road 
Rep Power: 6
Solved Threads: 90
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Posting Maven

Re: Help with making decimals show up always

  #2  
Nov 15th, 2007
Use the method
variablename.toFixed(2)
in your statement placing the value in the field (Where 'variablename' is, put the name of your variable).
Last edited by MidiMagic : Nov 15th, 2007 at 1:25 am.
Daylight-saving time uses more gasoline
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 3:59 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC