How to format MX number from 2000000 into readable 2,000,000?

Hi, my name is IGX and I have question :

Is there anyway in Flash to format displayed number with comma or decimal point for example : 2000000 should be displayed as 2,000,000 for more ease to our eyes, is there any available way ?

Thank you.

  • IGX
    :stuck_out_tongue:
function fDisplayNumber(nNumber) {
	nNumber += "", nTemp = (nNumber.length)%3;
	if (nTemp>0) {
		var sTemp = nNumber.substr(0, (nNumber.length)%3)+",";
	} else {
		var sTemp = "";
	}
	for (var ii = nTemp, jj = 0; ii<nNumber.length; ii++, jj++) {
		if (jj%3 == 0) {
			sTemp += nNumber.substr(ii, 3)+",";
		}
	}
	sTemp = sTemp.substr(0, sTemp.length-1);
	return (sTemp);
}

that should cover the commas for you.
Jeremy

Hi friend thank you for your help, but there is small small error said Flash MX, like the “;” and “{” which I dont understand where to place…

mmmmm, please help me, I’m not good in this…

Thank you

  • IGX / Akiko:chinaman:
fNum = function(n, s) {
	var n = n.toString(), l = n.length-1, i, t;
	for (i=0; i<=l; i++) {
		t += n.charAt(i);
		if (i<l && (l-i)%3 == 0) t += s;
	}
	return t;
}
trace(fNum(2000000, ","));

:wink: =)

KAX AND SINFINITI IS THE GREAT.

IT’S WORKING NOW - IM SO HAPPPPPYYYY !!! :phil:

SINFINITI GAVE ME THE START

AND KAX PERFECTS IT ALRIGHT

THANK YOU MY E-FRIENDS !!!

LOVE YOU ALL

PEACE

:rambo:

  • Love Akiko - South Korea

glad you liked it. :wink: =)

Of Course Kax

:link: :egg: :egg: :egg: :stuck_out_tongue:

nice one kax, i prefer your function to mine definitely!
:slight_smile:

scuse me…can anyone explain abit about the script…coz im not that good at it…and i want to learn how…thanks…