Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

comma(,) after 3 digits

Engaged ,
May 25, 2012 May 25, 2012

i trying ot add comma(,) after 3 digits to my result value.

but result first time is good, and 2nd time is result changed (not correct result value)

my code:

var reg:RegExp = /\d\d\d$/g;

var a:Array = new Array();

var res:String ='';

var dnSpeeds:String;

  dnSpeeds = e.params.bandWidth;

  downSpeeds.text = dnSpeeds + " Kbps";

  downTest();

while (dnSpeeds.length > 3){

          a.push(','+dnSpeeds.match(reg));

          dnSpeeds = dnSpeeds.replace(reg,'');

          }

          for (var i:int = a.length; i > 0; i--){

          res = res+a[i-1];

          }

          res = dnSpeeds+res;

          trace(res);

function downTest()

{

if (Number(dnSpeeds) >= 512)

          {

  Pass.visible = true;

  Fail.visible = false;

          }

else{

  Pass.visible = false;

  Fail.visible = true;

          }

}

TOPICS
ActionScript
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 25, 2012 May 25, 2012

search for "number formatting flash as3" to find formatting that does what you want.  for example,

http://stackoverflow.com/questions/721304/insert-commas-into-number-string

Translate
Community Expert ,
May 25, 2012 May 25, 2012

search for "number formatting flash as3" to find formatting that does what you want.  for example,

http://stackoverflow.com/questions/721304/insert-commas-into-number-string

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 25, 2012 May 25, 2012

yaa i tried this example. working

thank you guys,

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2012 May 26, 2012
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 25, 2012 May 25, 2012
I used this function, I found somewhere that I can not remember

function addCommasToNumber(number:Number):String

{

    var negNum:String = "";

    if (number<0)

    {

        negNum = "-";

        number = Math.abs(number);

    }

    var num:String = String(number);

    var results:Array = num.split(/\./);

    num = results[0];

    if (num.length > 3)

    {

        var mod:Number = num.length % 3;

        var output:String = num.substr(0,mod);

        for (var i:Number = mod; i<num.length; i += 3)

        {

            output += ((mod == 0 && i == 0) ? "" : ",")+num.substr(i, 3);

        }

        if (results.length > 1)

        {

            if (results[1].length == 1)

            {

                return negNum+output+"."+results[1]+"0";

            }

            else

            {

                return negNum+output+"."+results[1];

            }

        }

        else

        {

            return negNum+output;

        }

    }

    if (results.length > 1)

    {

        if (results[1].length == 1)

        {

            return negNum+num+"."+results[1]+"0";

        }

        else

        {

            return negNum+num+"."+results[1];

        }

    }

    else

    {

        return negNum+num;

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines