Forum Discussion

lucky_star's avatar
lucky_star
Occasional Contributor
8 years ago
Solved

How to format Numeric using 1000 Separator ","

Hi,

 

Please help me to format the numeric which is used 1000 Separator ","

 

value1= "2,400";
value2 = "1";

 

value = aqConvert["VarToFloat"](value1) + aqConvert["VarToFloat"](value2);

 

>> the result value is "2401"

 

Expected that the value is format is "2,401"

 

Thanks for your helping

  • Interesting.  I could only manage to print numbers with thousand separators using the deprecated functions:

     

    // JScript
    function thousand()
    {
      var aaa = 1234.1;
      Log.Message(Utilities.FormatFloat("#.#,", aaa));  // 1,234.1
      Log.Message(Utilities.FormatFloat("#.#",  aaa));  // 1234.1
      Utilities.ThousandSeparator = ";";
      Log.Message(Utilities.FormatFloat("#.#,", aaa));  // 1;234.1
      Log.Message(Utilities.FormatFloat("#.#",  aaa));  // 1234.1
    }
  • HKosova's avatar
    HKosova
    8 years ago

    lucky_star wrote:

    In this case, I expect that the result is format result as "1,234.10" , but the result is returned "1,234.1"

    So how can I format decimal places = 2 ?


    Log.Message(Utilities.FormatFloat("#.00,", 1234.1)); // 1,234.10

    should do the trick.

     

    Or if you would like to avoid using the deprecated Utilities functions, try this: 

    var number = 1234.1;
    var str = dotNET.System.String.Format("{0:n2}", number).OleValue; // 1,234.10

6 Replies

  • Ravik's avatar
    Ravik
    Super Contributor

    Function fun_RemoveSplChar(strToClean) 

    Dim objRegExp, outputStr

    Set objRegExp = New Regexp

    objRegExp.IgnoreCase = True

    objRegExp.Global = True

    objRegExp.Pattern = "[($?*"",\\<>&#~%{}+_@:\/!;]+"

    outputStr = objRegExp.Replace(strToClean, "")

    fun_RemoveSplChar = outputStr 

    End Function

     

    intNumber= fun_RemoveSplChar(1,000)

     

     

    Use above code it will remove all specified special character including , it will format your values like (1,000 = 1000)

     

    This may help you :)

    • joseph_michaud's avatar
      joseph_michaud
      Moderator

      Interesting.  I could only manage to print numbers with thousand separators using the deprecated functions:

       

      // JScript
      function thousand()
      {
        var aaa = 1234.1;
        Log.Message(Utilities.FormatFloat("#.#,", aaa));  // 1,234.1
        Log.Message(Utilities.FormatFloat("#.#",  aaa));  // 1234.1
        Utilities.ThousandSeparator = ";";
        Log.Message(Utilities.FormatFloat("#.#,", aaa));  // 1;234.1
        Log.Message(Utilities.FormatFloat("#.#",  aaa));  // 1234.1
      }
      • lucky_star's avatar
        lucky_star
        Occasional Contributor

        Hi joseph_michaud,

         

        function thousand()
        {
        Utilities.ThousandSeparator = ",";
        var num = 1234.10;
        var res = Utilities.FormatFloat("#.#,", num);
        Log["Message"](res);
        }

        In this case, I expect that the result is format result as "1,234.10" , but the result is returned "1,234.1"

        So how can I format decimal places = 2 ? 

         

        Thanks for your helping,