By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,408 Members | 1,840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,408 IT Pros & Developers. It's quick & easy.

Formatting Numbers - Adding commas fails

P: 1
Hi guys,
Can someone please help me to Format Numbers with commas. The script below have very large number without commas. To read numbers in trillions and billions are hard, without commas to separate the numbers. By cutting and pasting the JavaScript below into a web editor and you can clearly see what is happening. Please, help. Thank You,
freemld10
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function startTime()
  5. {
  6. var seconds = 0;
  7. var secondsDifference = 0;
  8.  
  9. MyBirthDay=new Date("June 19, 1973");
  10. today=new Date();
  11. secondsDifference=MyBirthDay-today;
  12.  
  13. seconds=secondsDifference/(1000);
  14. minutes=seconds/60
  15. hours=seconds/(60*60)
  16.  
  17. document.getElementById('txt').innerHTML=("My life in Seconds from my Birthday " +seconds+ "<br>" +"My life in minutes from my Birthday " +minutes+ "<br>" +"My life in minutes from my Birthday " +Math.round(hours))
  18.  
  19. t=setTimeout('startTime()',1000)
  20. }
  21.  
  22. function checkTime(i)
  23. {
  24. if (i<10) 
  25.   {i="0" + i}
  26.   return i
  27. }
  28. </script>
  29. </head>
  30. <body onload="startTime()">
  31.       <b><font size="12px"><div id="txt"></div></font><br></b>
  32. </body>
  33. </html>
Sep 8 '07 #1
Share this Question
Share on Google+
2 Replies


pbmods
Expert 5K+
P: 5,821
Heya, freemld. Welcome to TSDN!

Please use CODE tags when posting source code:

[CODE=JavaScript]
JavaScript code goes here.
[/CODE]

What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Sep 8 '07 #2

gits
Expert Mod 5K+
P: 5,352
hi ...

may be the this post is of some help to you. you have to make some adaptions ... like:

in case your var-type is number -> make a string out of it:

Expand|Select|Wrap|Line Numbers
  1. var your_value = 13432343435;
  2. var str_value = new String(your_value);
  3.  
use str_value to start with the script in the post. now you should have a look at the regEx ... it should be adapted to match from the end :) try or ask again for that.

further: look at the join-method ... where you should replace '</wbr>' with ',' ...

kind regards
Sep 9 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.