Solved

How to format number

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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 …
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…

856 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