Convert & rounding an Excel cell

Hello dear RPA developers,

I’m trying to convert and round up an Excel cell but I struggle doing so as you may guess !
After looking the others related topics, I find always the same answers, but it’s not working, so here I am.

Surprisingly, it worked fine till today, but now I have this message

image

The cell I’m talking about:

image

So, if someone have an idea on how to resolve this as well as why it’s not working anymore, he is more than welcome to share it :slight_smile:

Thanks for reading and have a great day / week-end.

@ppr (I tag you because you are often in the answers I am looking for on the forum :relieved:)

1 Like

Hi,

is there any formatting on the cell? is it general / text/ number etc

Is there whitespace after the number?

If you can respond to those, I can take a look at what else might be causing the problem

Hey @Geoffroy_Pantegnies

Please replace , with empty string before you do the double conversion.

Thanks
#nK

Hi, thanks for answering !
I don’t know if it’s ‘general’ or ‘text’, but there is no white space after the number.

image

Hi ! Thanks for your answer but I’m not sure I’ve done what you meant to say.

(math.round((Convert.Todouble(Row(0).tostring.replace(“,”,“.”))),2).tostring).replace(“.”,“,”)

I assume the , in the number is a decimal point.

The above replaces the , with . then completes the rounding and reverts it back.

Another thing you could try first is Double.TryParse

as mentioned above:

  • reformat the cell - can be done with Balareva Change Cell Type Activity
  • do the conversion / rounding with UiPath essential activity

it is not recommended to fix alternate number format with string replaces, due we would prefer to have more control on sucess or failure on it.

decimal seperator fefined by a comma we do handle with locals

e.g. german number formats are defined like this
grafik

1 Like

Hi Lieehoma0, thanks for answering !

No whitespace before or after the number.

I tried your solution but I have the same error.
I cannot know if it’s a decimal point, we get the value from an ERP.

Could you elaborate with the Double.TryParse please ?

When I try in an assign I get “Overload resolution”

Hi Peter, thanks for answering :slight_smile: !

With the balareva activity I have this result, so I don’t know if it’s Number or text. What I know is I have the same error message 'input string was not in correct format), whatever the method I use (not that I know a lot): double.parse, or convert.todouble.

image

Your exemple is interesting but our number will never be this big luckily.

would suggest to attack the issue straightforward

  • whats coming inside (input)
  • select approvriate conversion

Controlling input:

  • Balareva
    *Conversion Functions

If 123,45 formats are to convert CDBL, Convert.ToDouble will fail on the comma
Double.Parse along with Cultures can handle (See above demo)

To check what is within the datatable we do debug and inspect with the different debig panels
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

1 Like

Thanks, I’ve managed to make it work thanks to your advices !

Have a nice day Peter

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