How to round number to thousand

i have use case where i have to add , to make number as thousand.
Eg. 40000.00 should be 40,000.00

3000 should be 3,000
like this

Lenght of the interger is not fixed

Hi @sshitol

This seems to be doing it:

1000.ToString("N2")

numbers need to be formatted with commas
e,g 39276.4 to be as 39,276.4

4000 to be 4,000

length of the number is not fixed… “,” should be in thousand format

Hi @sshitol

Try this approach

strNum = dblNum.ToString("N")

Hi @sshitol
If(inputNumber Mod 1 = 0, String.Format(“{0:N0}”, inputNumber), String.Format(“{0:N2}”, inputNumber))

Try this.

  1. Mod 1 = 0: Checks if the number is a whole number.
  2. String.Format(“{0:N0}”, inputNumber): Formats the number without decimals.
  3. String.Format(“{0:N2}”, inputNumber): Formats the number with two decimal places.

To handle your use case in UiPath, where numbers of varying lengths need to be formatted with a thousand separator while preserving decimal points, you can use the following approach:

Steps:

  1. Use a Numeric Variable:
    Ensure the input number is of type Double or Decimal to handle both integers and floating-point values.

  2. Format the Number with Thousands Separator:
    Use the .ToString method with the #,##0.00 format specifier. This format ensures:

    • Commas are added as thousand separators.
    • Two decimal places are retained (e.g., 40000.0040,000.00).
  3. UiPath Workflow Example:

    • Input Variable: inputNumber (type: Double or Decimal).
    • Formatted Output Variable: formattedNumber (type: String).
    • Assign Activity Code:
      formattedNumber = inputNumber.ToString("#,##0.00")
      
  4. Examples of Outputs:

    • Input: 40000.00 → Output: 40,000.00
    • Input: 3000 → Output: 3,000.00
    • Input: 1234567.89 → Output: 1,234,567.89

Complete UiPath Workflow Example:

  1. Read Input: Create an input variable (e.g., inputNumber).
  2. Format Number:
    • Use an Assign activity:
      formattedNumber = inputNumber.ToString("#,##0.00")
      
  3. Output Result: Display formattedNumber using a Message Box or write it to a file.

Would you like me to create a visual guide or a sample workflow file for you?