I have following columns in a table:
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)
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?
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
You can check the calculation by taking the values marked red.
Do you have any idea what I missed?
@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…
@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…
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?
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):
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.