Solved

Format number in javascript

Posted on 2014-04-07
3
226 Views
Last Modified: 2014-04-22
I have some input boxes on the screen to allow the user to type in the numbers.  I aslo have an input box to store the Total of all numbers above.  The input box for the Total cannot be changed and I want to display it as $12,345.67.  I use FormatCurrency(txtTotal,2) and the total show up as I want.  But then when I change one of the input numbers, the calculation is not correct.  When I remove FormatCurrency(), it works again.  Is there a way to make the calculation and display work at the same time?

Thanks,
0
Comment
Question by:ttta83
3 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39985024
I have never had luck with formatcurrancy and I simply add the $ sign as text and use css for formatting.

There may be a rounding issue.

I use
$<%=formatnumber(txtTotal,2)%> or 
<%
response.write "$" & formatnumber(txtTotal,2)
%>

Open in new window

If you are doing any type of division, you need to first do your rounding.  http://www.w3schools.com/vbscript/func_round.asp
response.write(Round(24.53278,2)) ' = 24.53
response.write(Round(24.539122,2),2) ' = 24.54

%>

Open in new window

Putting it together
txtTotal=24.586
txtTotal=round(txtTotal,2) ' = 24.59
response.write "$" & formatnumber(txtTotal,2) ' $24.59

Open in new window

0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39985310
Can you post the code of your format function?
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

777 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