I’m new to UIpath and I stumbled across a problem I’m unable to solve. I have a datatable with string values (obtained through data scraping), of which I want to convert some to decimal values (see example below). Convert.ToDecimal() doesn’t seem to apply on datatables (or datacolumns).
col1 col2 col3
“10.12” “name1” “9.64”
“14.31” “name2” “2.40”
col1 col2 col3
10.12 “name1” 9.64
14.31 “name2” 2.40
Any advice on how I could achieve this? Many thanks in advance!
Have you tried Convert.ToDouble(“your value”)
Thanks to your help, I managed to figure it out! Turns out my row-iteration was wrong, after fixing that the ‘normal’ Convert.ToDecimal worked out perfectly in an assign activity.
- Use a for each row activity to iterate over cell values (within the datatable)
- Use an assign activity to perform the following operation:
a. row.Item(“col1”) = Convert.ToDecimal(row.Item(“Col1”))
It should look something like this:
*where DT is the example datatable
NB: while performing this operation on currency data, it failed on strange symbols (€), so I used @MAHESH1’s solution to keep only numerical values from a string:
string b= System.Text.RegularExpressions.Regex.Replace(“string_Variable”,"\D","")
Once again, thanks for all the help!
Kind regards, Mark
I’m glad you got it fixed. Also thanks for sharing the solution, it will help someone on the community.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.