Solved

How to format number

Posted on 2002-04-26
3
570 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

785 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