How to divide three values while keeping the decimals?

I have following columns in a table:
grafik
At the end I need to divide for each row…
“Courtage” / “Courtagesatz” / 1000
First I calculate the second part (“Courtagesatz”/1000) which is working and giving me the correct result (marked red in screenshot below)

grafik

The first value (“Courtage”; marked yellow) is also generated correct from the datatable - but as a string!
When I now try to convert it to integer the decimals get lost.
So how I can keep them?
And what kind of variables do I need to specify???
Int32, Double?

@MarcJo

You need to declare variable as Double but not Integer type.

Pls learn a bit about data types here
https://docs.uipath.com/studio/docs/types-of-variables

or better here

Cheers

1 Like

Hi @lakshman,
thanks for your help but apparently I missed something…
My Assign activity says:
Berechnungsgrundlage_Friends (Double) = Convert.ToDouble(Provision_Friends) (String) /Provisionssatz_Friends_2 (Double)
But the result (marked yellow) is wrong by 2 decimals

grafik

You can check the calculation by taking the values marked red.
Do you have any idea what I missed?

Hi @MarcJo,

You can use:

Convert.ToDouble(variable)

Hi @rmunro,
as mentioned in my last comment I already tried that but it did not work.
The comma has not been recognized as it seems

@MarcJo,

For example the first value shouldn’t be 1.37 instead of 1,37?

@MarcJo your excel is formated as numbers, you get yourself more trouble than needed, everytime you do row(0).ToString to look at the value, you think it has the wrong format, but it is you actually that is converting it to string… just dont do that, work with the data as it is and you will be ok, only if you need to write those numbers in a text format, you use that ToString…

1 Like

@rmunro,
yes it should always be a comma instead of a dot → so 1,37 instead of 1.37

@bcorrea but if I do not convert it to String I get the notification that I cannot convert Object to Generic Value or Integer.
So how else can I take all the values from a specific column and calculate with them?

You cant calculate anything with a string… as people try to tell you, every column in your datatable will have a type, you need to understand that, so you can better work with your data, for that column, if you need to do some mathematics expression, then never use ToString, use CDbl(row("Courtage")) or Convert.ToDouble(row("Courtage")) and NEVER do ToString, not even to look if it has the format you want, cause that will jsut confuse you…

1 Like

I know that I cannot calculate with a string.
But when I put
DoubleVar = Cdbl(row(8) I do not get the comma!
Instead of 128,26 I get 12826.
So what kind of data type do I have to choose or how do I have to manipulate it in order to get the decimals?

@MarcJo,

You have to change that comma. Either with a period or just delete it if it’s not necesary. If you need the comma back again then just add it again by replacing again the period by comma

Sorry, but you are failing to understand my point… How do you even know that your conversion is losing those decimals? No one that is not a developer will be able to turn themselves into one just by using UiPath, that takes us several years of learning… just trust me when a say this, if your excel does have a number like “128,26” and you read that into a datatable, that decimal will be preserved, unless you remove that yourself with a wrong conversion…

@bcorrea @rmunro
Apparently the decimals are not recognized as you can see in my output…

This table is the basis - the relevant columns are “Courtagesatz” and “Courtage” (both selected; grey):

grafik

Now I take the value of “Courtagesatz” and divide it by 1000 - result is 0,056 (put into variable XYZ)
→ correct

Then I take the value of “Courtage” (128,32) and divide it by variable XYZ (0,056) - result is 229142,428…
not correct! The actual result should be 2291,428… So apparently there is mistake with the decimals.

can you share your excel? i would just do a file with your simple test to show my case.

It’s actually a csv file.
So I changed it to .xlsx

Test_file_2.xlsx (9.9 KB)

Hey @MarcJo,

Try Parsing the numbers like this

Double.Parse(row(“columnName”).ToString,System.Globalization.CultureInfo.CurrentUICulture)

You can read more about parsing here:

1 Like

Sequence1.xaml (4.4 KB)
see my example

@aeklof,
the commas were again not recognized - see screenshot below (marked yellow):

grafik

This is what I did:

Berechnung_Teil1 =
Double.Parse(row(“Courtage”).ToString,System.Globalization.CultureInfo.CurrentUICulture)

Berechnung_Teil2 = Double.Parse(row(“Courtagesatz”).ToString,System.Globalization.CultureInfo.CurrentUICulture)/1000