/    Sign up×
Community /Pin to ProfileBookmark

Formatting Numbers

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 you can clearly see what is happening. Please, help. Thank You,
freemld10

<html>
<head>
<title>Untitled</title>
<table width=”750″>
<tr>
<td align=”center”><h2>Days From Michael 21st Birthday</h2>
<form name=”count”>
<br><input type=”text”; font-family: verdana; font-size=”20″; size=”50″; name=”count2″>
</form>
<td>
</tr>
</table>
<script LANGUAGE=”JavaScript”>

/*
Count down script-
By JavaScript Kit ([url]www.javascriptkit.com[/url])
Over 200+ free scripts here!
*
/

//change the text below to reflect your own,
var before=”seconds”
var current=”Today is Year 3000!”
var montharray=new Array(“Jan”,”Feb”,”Mar”,”Apr”,”May”,”Jun”,”Jul”,”Aug”,”Sep”,”Oct”,”Nov”,”Dec”)

function countdown(yr,m,d){
theyear=yr;themonth=m;theday=d
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+” “+todayd+”, “+todayy+” “+todayh+”:”+todaymin+”:”+todaysec
futurestring=montharray[m-1]+” “+d+”, “+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*
60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
if(dday==0&&dhour==0&&dmin==0&&dsec==1){
document.forms.count.count2.value=current
return
}
else
document.forms.count.count2.value=dday+ ” days, “+dhour+” hours, “+dmin+” minutes, and “+dsec+” “+before
setTimeout(“countdown(theyear,themonth,theday)”,1000)
}
//enter the count down date using the format year/month/day
countdown(1973,6,19)
</script>

<script LANGUAGE=”JavaScript”>
<!–
// Javascript Countdown
// Version 1.0 1/20/2000
// by TDavid at [url]http://www.tdscripts.com/[/url]
var now = new Date();
var event = new Date(“june 19 1973 00:00:01”);
var seconds = (event – now) / 1000;
var minutes = seconds / 60;
var hours = minutes / 60;
var days = hours / 24;
var weeks = days / 7;
var months = days / (365/12);
var years = days / 365
ID=window.setTimeout(“update();”, 1000);
function update() {
now = new Date();
seconds = (event – now) / 1000;
seconds = Math.round(seconds);
minutes = seconds / 60;
minutes = Math.round(minutes);
hours = minutes / 60;
hours = Math.round(hours);
days = hours / 24;
days = Math.round(days);
weeks = days / 7;
weeks = Math.round(weeks);
months = days / (365/12);
months = Math.round(months);
years = days / 365;

document.form1.seconds.value = seconds;
document.form1.minutes.value = minutes;
document.form1.hours.value = hours;
document.form1.days.value = days;
document.form1.weeks.value = weeks;
document.form1.months.value = months;
document.form1.years.value = years;

ID=window.setTimeout(“update();”,1000);
}

// –></script>

</head>

<p><font face=”Arial” size=”3″></font></p>

<form name=”form1″>
<br>
<table width= “720” border=”2″>
<tr>
<td colspan=”3″ align=”center”><b><font size=”5″ color=red face=”Arial, Geneva” >MICHAEL’S <br>Birthday CLOCK!!!</hr></font></br>
</td>
</tr>
<tr>
<td>Birthday Seconds—from June 19, 1973</td>
<td><input type=”text” name=”seconds” value=”0″ size=”10″></td>
<td>SECONDS</td>
</tr>
<tr>
<td>Birthday Minutes—-from June 19, 1973</td>
<td><input type=”text” name=”minutes” value=”0″ size=”10″></td>
<td>MINUTES</td>
</tr>
<tr>
<td>Birthday Hours——from June 19, 1973</td>
<td><input type=”text” name=”hours” value=”0″ size=”10″></td>
<td>HOURS</td>
</tr>
<tr>
<td>Birthday Days——-from June 19, 1973</td>
<td><input type=”text” name=”days” value=”0″ size=”10″></td>
<td>DAYS</td>
</tr>
<tr>
<td>Birthday Weeks—–from June 19, 1973</td>
<td><input type=”text” name=”weeks” value=”0″ size=”10″></td>
<td>WEEKS</td>
</tr>
<tr>
<td>Birthday Months—-from June 19, 1973</td>
<td><input type=”text” name=”months” value=”0″ size=”10″></td>
<td>MONTHS</td>
</tr>
<tr>
<td>Birthday Years——from June 19, 1973</td>
<td><input type=”text” name=”years” value=”0″ size=”10″></td>
<td>YEARS</td>
</tr>
</table>

</head>
<body>

</body>
</html>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@DARTHTAMPONAug 23.2007 — number = number.replace(/d{3}$/g, "," + number[1]);

your number find 3 digits

starting from the right side

globle (find many instances)

replace with , and your 3 digits

not tested but I would guess this should work.
Copy linkTweet thisAlerts:
@felgallAug 24.2007 — See http://javascript.about.com/library/blnumfmt.htm for a function that can apply all sorts of formatting to numbers including comman insertion.
×

Success!

Help @freemld10 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...