Hi, I want to change the data gathered from a csv file into having 2 decimal places at the end. This is because I have to compare them with an extracted datatable, which holds the same value but with proper 2 decimal places because it is based on the currency format (but I don’t think it is saved as such).
For example:
Extracted Datatable:
45.80
1232.60
CSV Datatable:
45.8
1232.6
The amounts with no cents at the end have no problem though. If there’s no way to exclude whole numbers like those with no cents value at the end, I’d have to do the same with the Extracted Datatable.
I need to do this for two columns, Deposit and Withdrawal. Because they both hold the values that I need to use to compare my datatables with.
Since I have to compare them but the CSV Datatable don’t have 0’s at the end, they are not detected by my RPA. I heard using LINQ is the fastest and easiest method but I’ve looked it up and attempted to do some based on certain posts to no avail. If someone would kindly guide me on how it can be done I would be very grateful. Thank you
dt.AsEnumerable().ToList().ForEach(Sub(row)
If row("Deposit").tostring.contains(".") Then
row("Deposit")= Convert.ToDouble(row("Deposit")).ToString("N2")
End If
If row("Withdrawal").tostring.contains(".") Then
row("Withdrawal")= Convert.ToDouble(row("Withdrawal")).ToString("N2")
End If
End Sub
)
then set arguments to this (make sure direction is in/out)
Do you think this code adds “,” for amounts that reaches thousands? Asking because this is the output of datatable that I got (I yellowed out the amounts that has “,” added.
Whereas before the invoke code, this is the output (ignore the yellowed cells, I did it to bring attention to amounts with no 0s after the decimal place.)
dt.AsEnumerable().ToList().ForEach(Sub(row)
If row("Deposit").tostring.contains(".") Then
row("Deposit")= Convert.ToDouble(Convert.ToDouble(row("Deposit")).ToString("N2")).ToString("N")
End If
If row("Withdrawal").tostring.contains(".") Then
row("Withdrawal")= Convert.ToDouble(Convert.ToDouble(row("Withdrawal")).ToString("N2")).ToString("N")
End If
End Sub
)
dt.AsEnumerable().ToList().ForEach(Sub(row)
If row("Deposit").tostring.contains(".") Then
row("Deposit")= Convert.ToDouble(row("Deposit")).ToString("N2").Replace(",","")
End If
If row("Withdrawal").tostring.contains(".") Then
row("Withdrawal")= Convert.ToDouble(row("Withdrawal")).ToString("N2").Replace(",","")
End If
End Sub
)