For each Row in data table format row

I have a CSV with three colums.
In a colum named “Additional Discounts” i have values that are either xx , xx% or 0.xx
for each of those cases i want to format the row to be xx

Can anyone help ?

I tired an assign with : CorrectedDiscount = Convert.ToInt32(row(“Additional Discount”).ToString)*(100)
but i get an error: Assign : Input string was not in a correct format.

what is the type of CorrectedDiscount .?
when you trying to convert everything into int xx formate

  1. if it is XX% then
    have if condition and check if row.item('additional Discount").tostring.contains(“%”)
    – then your % to int conversion code
    else check if irow.item('additional Discount").tostring.contains(“.”) then convert this string to decimal and then round off the value.

Corrected discount is just a temporary variable i use to place the corrected info back into the original Data table.

At the end i need to end up with the same CSV but with the discounts properly formated.

this you can achieve by creating new data table using build data table with same columns
once you done with calculation as mentioned above then add new values to new data table built and at end write new data table to excel.

could you please show me an example ?

I managed to make it work with a weird workaround.

  1. if your input .xlsx/.xlsm has values that are either 0.00 , 0.00% or 0 then import the excel as datatable
    then export the data table as CSV;
  2. import the CSV as a data table and now all 0.00% have been converted to 0.00 by the CSV export function;
  3. for each row in the CSV’s data table if you find the row to contain “0.” then multiply by 100
    for each row in datatable:
    if row.Item(column index of your value).ToString.Contains(“0.”)
    then row.i=Item(column index of your value) = (Convert.ToDouble(row(column index of your
  4. export the new data table back to your desired location.
1 Like