[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Formatting the sum into currency in JavaScript function

Posted on 2012-08-22
4
Medium Priority
?
432 Views
Last Modified: 2012-08-22
function updatesum() 
{
	document.travTranFrm.sum.value = (document.travTranFrm.trainingCosts.value -0) + (document.travTranFrm.travelCosts.value -0); 
} 

Open in new window


How would I make the output of this appear as currency. For example, training costs is 1,200.00 and travel costs are 60.00 - the sum appears as 1260 as this is written now. Would I do that on the JavaScript end or would I at the output:

$<input name="sum" readonly style="border:0px;">

Open in new window


Many thanks!
0
Comment
Question by:traport
  • 2
  • 2
4 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 38321587
outputVal= parseFloat(inputVal).toFixed(2);



Cd&
0
 

Author Comment

by:traport
ID: 38321790
Thanks. Where would I put that in the code? Sorry...
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 2000 total points
ID: 38321835
function updatesum() 
{
	document.travTranFrm.sum.value = parseFloat((document.travTranFrm.trainingCosts.value -0) + (document.travTranFrm.travelCosts.value -0)).toFixed(2);
} 

Open in new window


                                 

Cd&
0
 

Author Closing Comment

by:traport
ID: 38321888
Thanks a lot!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question