Format number in javascript

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?

Who is Participating?
Scott Fell, EE MVEConnect With a Mentor Developer & EE ModeratorCommented:
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.
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=round(txtTotal,2) ' = 24.59
response.write "$" & formatnumber(txtTotal,2) ' $24.59

Open in new window

Can you post the code of your format function?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.