Unable to Truncate decimal places from decimal values of a column in Datatable

Hi, There is a Datatable which has column values as decimal numbers, need to truncate the decimal values and maintain only the whole number.I do not want to round of the values but just maintain the whole number and remove the decimal places:

Example: 888967.73 to be converted to 888967

Trying to use the below and assigning it back to dptDT Datatable, but it doesn’t seem to be truncating the decimal places:

dptDT.AsEnumerable().OrderBy(Function(r) Convert.ToString(r(“Amount”).ToString.Split("."c)(0))).ToArray().CopyToDataTable()

Referred the below link, which needs iteration of the entire Datatable to change the values:

There are around 4000 rows in the Excel sheet, and iterating and truncating is taking a long time in executing the workflow.

Is there anyway to convert all the column values in one single query on the Datatable. Please let me know

Followed the below link as well to use LINQ query for updating Column values of a Datatable

getting this error even after adding the DataSetExtensions following the link

You will need to copy from one DT to another like follows:

dt2 = (From row In dt1.AsEnumerable
Select dt2.rows.Add(CStr(row.Item(0)).Split("."c)(0))).copytodatatable


1 Like

Thanks will try that


Thanks for the inputs the issue is resolved now …following the steps above updating the existing Datatable column values without creating new Datatable. Used Invoke Code activity to call the below code, Also referred the below link:

DataTable.AsEnumerable().ToList().ForEach(Sub (r) r.SetField(Of String)(“Amount”, CStr(r.Item(3)).Split("."c)(0)))


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