Forum Discussion

dpeterson157's avatar
dpeterson157
Contributor
11 years ago

Use aqString.format to generate a number with the thousands separator

It can't possibly be this hard, but I can't for the life of me figure out how to do it!



What I want:



aqString.Format("???", 1) = 1

aqString.Format("???", 100) = 100

aqString.Format("???", 100000) = 100,000

aqString.Format("???", 10000000) = 10,000,000



What does "???" need to be?



No examples in Smartbear documentation for creating this format.



  • Hi David,

     

    As far as I know, aqString.Format cannot do this, but you can use the .NET System.Format method instead:
    // JScript
    dotNET.System.String.Format("{0:n0}", 1000).OleValue

    It uses the current locale's thousands separator - comma/space/period etc.

     

    If you run tests on different locales and want to always format with a comma, you can use something like this:
    // JScript
    function ToString(number)
    {
    var culture = dotNET.System_Globalization.CultureInfo.zctor("en-US");
    var args = dotNET.System_Collections.ArrayList.zctor();
    args.Add(number);
    var str = dotNET.System.String.Format_3(culture, "{0:n0}", args.ToArray()).OleValue;
    return str;
    }
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi David,

     

    As far as I know, aqString.Format cannot do this, but you can use the .NET System.Format method instead:
    // JScript
    dotNET.System.String.Format("{0:n0}", 1000).OleValue

    It uses the current locale's thousands separator - comma/space/period etc.

     

    If you run tests on different locales and want to always format with a comma, you can use something like this:
    // JScript
    function ToString(number)
    {
    var culture = dotNET.System_Globalization.CultureInfo.zctor("en-US");
    var args = dotNET.System_Collections.ArrayList.zctor();
    args.Add(number);
    var str = dotNET.System.String.Format_3(culture, "{0:n0}", args.ToArray()).OleValue;
    return str;
    }