Converting column values to decimal upto 2 values

I have a sheet where I need to convert the values of some columns into decimal values upto 2 decimals.
the column names are:-
I have attached a sheet for the same.
Test2.xlsx (10.3 KB)
Can anyone let me know how to do it??


if the conversion is needed in excel then use format cells activity



Use invoke code activity and pass this

        row.SetField("decimal1", String.Format("{0:0.00}", Convert.ToDouble(row("decimal1").ToString)))
        row.SetField("decimal2", String.Format("{0:0.00}", Convert.ToDouble(row("decimal2").ToString)))
        row.SetField("decimal3", String.Format("{0:0.00}", Convert.ToDouble(row("decimal3").ToString)))
        row.SetField("decimal4", String.Format("{0:0.00}", Convert.ToDouble(row("decimal4").ToString)))
        row.SetField("decimal5", String.Format("{0:0.00}", Convert.ToDouble(row("decimal5").ToString)))        
    End Sub

Pass datatable variable with argument property

Hope this helps

Cheers @Kunal_Jain

Hi @Palaniyappan
Can you help me with the workflow please if possible?
Thanks in advance!!

1 Like

Check this out
use write range activity to write it to an excel file (3.1 KB)

hope this helps

If its clarified, would recommend to close this topic

Cheers @Kunal_Jain

Hope this helped @Kunal_Jain

Hi @Palaniyappan
It is giving me the error after attaching the data from the above provided excel
The error is:-
Invoke Code: Exception has been thrown by the target of an invocation.
Thanks in advance!!

1 Like

Did u make any changes to the code @Kunal_Jain

Hi @Palaniyappan
Yes I have added an excel application scope and a read range activity.
And commented out the code of build data table.

Then I hope u have used the same datatable variable name
Run in debug mode to check what error has occurred


Yes I have used the same data table variable name and it is giving me the same error which I mentioned.
If you want I can share my updated workflow (3.6 KB)

My excel is crashed so couldn’t include with excel that’s why I gave with datatable
To debug I can suggest in a way like

  1. Check with column names in the linq code
  2. Check with arguments whether u have passed the arguments correctly or not
  3. Run in debug mode and share the exception u r getting


It is giving the same error.

Can u share the exception message a screenshot if possible and also ur invoke code screenshot

Hi @Kunal_Jain ,

Could you check by adding the Try Catch blocks to the Invoke Code Expression, it will help us to target the Error and get a clear Error message from it :

The Error message will be present in the Output Panel once it executes.

Hi @Palaniyappan and @supermanPunch
There was an empty column that we were sending.
The code is working but can we add an extra validation regarding empty column.

1 Like

Hope it all clear now

Yeah you can add but that empty column cannot be added to the above code in INVOKE CODE activity as the above code tries to round of the value present in the highlighted column but your new column doesn’t have any value


Thanks for the Solution!!

1 Like

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