Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Format number in javascript

Posted on 2014-04-07
3
227 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
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…

838 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