How to find out how many decimal places a number has

Hello everyone!

I can’t seem to find a solution to the following problem: how can I find out how many decimal places a number (assigned to a variable from Excel) has? The number needs to have exactly two decimal digits, if it has more, UiPath is supposed to throw an error.

Example (in a if condition):
Number 20,33 → then it’s correct and the process continues
Number 20,331 → else process should be stopped

Thank you in advance!

Hi,

I am not sure whether you are referring the “.” with “,”. Anyway we can use the string manipulations to find out how many decimals there in that string. I assume the value mentioned are string type. use below expression for if condition.

YourValue.split(","c)(1).length = “2” pls proceed or throw exception using throw activity. please let me know if you need any additional help. thanks.

Hi, @G_rt ,

Try the below logic, also attaching the XAML file.

Logic :

  1. yourNumber = “123.21”
  2. (yourNumber.Substring(yourNumber.IndexOf(“.”) + 1).Length).ToString

Code :
Get Decimal Count.zip (2.4 KB)

Screenshot :
Capture