How to change string format

in excel, my amount column values is given as:
25000
5000
1000
0
2500
10000
500

can anyone give me string manipulation method to get values as follows:
25,000
5,000
1,000
0
2,500
10,000
500

Use for each

then use format value activity
in that select number
image

Hope this helps

@Mohammad.Fuad

  1. Select the cells containing the “Amount” values that you want to format.
  2. Right-click and choose “Format Cells” or press Ctrl + 1 to open the Format Cells dialog.
  3. In the “Number” tab, select the “Custom” category on the left.
  4. In the “Type” input box, enter the following custom number format:
    #,##
    Click “OK” to apply the custom format.

Your values will now be displayed in the desired format:

  • 25,000
  • 5,000
  • 1,000
  • 0
  • 2,500
  • 10,000
  • 500

HI @Mohammad.Fuad ,
Have you tried it
https://docs.uipath.com/activities/other/latest/productivity/format-range-x

@Usha_Jyothi
Capture3

how to obtain only 1,000 . I dont want decimal points.

Hi @Mohammad.Fuad

Try this

@Mohammad.Fuad

use this Linq:

Assign activity:

(From row In inputDataTable.AsEnumerable()
                                Let formattedAmount = If(String.IsNullOrEmpty(row("Amount").ToString()), "", 
                                                       If(IsNumeric(row("Amount").ToString()), 
                                                          Convert.ToDecimal(row("Amount")).ToString("N0"), 
                                                          row("Amount").ToString()))
                                Select New With {
                                    .Amount = formattedAmount
                                }).CopyToDataTable()

Cheers…!

then remove the value after decimal
using regex or split function

@Mohammad.Fuad

str_input=“25000”

String.Format(“{0:N0}”,cint(str_Input))

image

ByUsing Invoke Code

Output

1 Like

Hi @Mohammad.Fuad

Try this:

- Read Excel File (e.g., "Read Range" activity into dtExcel)
- For Each Row (in dtExcel)
  - Assign: row("Amount") = String.Format("{0:N0}", Double.Parse(row("Amount").ToString()))
- End For Each
- Write Excel File (if needed)

Hope it helps!!

1 Like

Hi,
you can use below expression:

row(“Amount”) = String.Format(“{0:N0}”, Convert.ToInt32(row(“Amount”).ToString))

  1. row("Amount"): This is where we look at the value in the “Amount” column of the data.

  2. Convert.ToInt32(row("Amount").ToString): We take that value and make sure it’s treated as a whole number (integer) even if it was in a different format.

  3. String.Format("{0:N0}", ...): This part is like a command to format the number we just converted. {0:N0} means “format the number with no decimal places and add commas for thousands.”

  4. row("Amount") = ...: Finally, we replace the original value in the “Amount” column with the newly formatted one. So if the original value was 25000, it will now be 25,000.

it takes a number from Excel data, turns it into an integer (a whole number), and then makes it look nice with commas for thousands.

Hi @Mohammad.Fuad

try this
image

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.