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);   >>...
  • joseph_michaud's avatar
    8 years ago

    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