Solved

How to format number

Posted on 2002-04-26
3
572 Views
Last Modified: 2008-02-01
How do you format a javascript number as 9,999,990.00 as in java
0
Comment
Question by:EdwardSee
[X]
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
3 Comments
 
LVL 1

Accepted Solution

by:
rajeev1972 earned 50 total points
ID: 6972893
Use this sample

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function addComma(numVar)
{
     var formattedNumber="";
     var commaNumber = "";
     var j = numVar.indexOf(".");

     if (j != -1)
     {
          for(i = numVar.length; i>j; i--)
          {    
               formattedNumber = formattedNumber + numVar.charAt(i-1);
          }
     }
     else
          j = numVar.length;

     for (i = j; i > 0; i--)
     {
          if ( (i != j) && ((j - i) % 3 == 0))
                 formattedNumber = formattedNumber + ",";
          formattedNumber = formattedNumber + numVar.charAt(i-1);
     }
     for (i = formattedNumber.length - 1; i >= 0; i--)
          commaNumber = commaNumber + formattedNumber.charAt(i);
     return commaNumber;
}

//-->
</SCRIPT>
</HEAD>

<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
alert(addComma("12312321.9800"));
//-->
</SCRIPT>
</BODY>
</HTML>
0
 
LVL 12

Expert Comment

by:ahosang
ID: 8131937
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

points to rajeev1972
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
ahosang
EE Cleanup Volunteer
0
 

Expert Comment

by:modulo
ID: 8191426
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Title # Comments Views Activity
Sending ASP to server side 8 31
Any Way to rotate banner ads from Commission Junction? 2 37
Two decimal 5 27
Slush on text 2 11
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

749 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