# 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 https://stackoverflow.com/questions/13903621/convert-a-text-fraction-to-a-decimal 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.

Cheers!

@HiteshJeswani101

Try this.

``     CDbl(1/2)``
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?

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.