How do i convert "1/2" string to 1/2 expression?

example: 1/2 in string to 0.5 in decimal

Hey, there is no direct method available in .net. However you can create a logic which convert fraction text to decimal value. I have used and it works. I had a similar requirement.

You can implement the same logic in UiPath and create a Library or create a custom activity.



Try this.

1 Like

This would not work I guess as input format is in Text.

CDbl(“1/2”) --> This will throw an exception.

Hi @lakshman can you please elaborate on it?

What i want is to convert string to a fraction.
Example: CDbl(“1/2”) to 0.5 decimal
is this possible?

Hi @HiteshJeswani101,

If, Str1 (String) = “1/2”
Then, use assign

Number (Double) = CDbl(CDbl(str1.Split("/"C)(0))/CDbl(str1.Split("/"C)(1)))

writeline —> Number.Tostring
You’ll see the output —> 0.5

1 Like

Also we need to check the second part is not a “Zero”

I don’t think so @sarathi125

  1. If numerator is 0 then it’ll give output as 0.
  2. If denominator is 0 then it’ll give output as Infinity.

Which is correct.