Regex not working in UiPath; regex works on regex builder websites

I have the following sample data:

I am trying to use System.Text.RegularExpressions.Regex.Replace(testStr,"(^-?\d{1,9}.\d{1})",testStr+"0") to format the data to have two digits after the decimal for any items in the test data that only have one digit after the decimal. I have tried different version of the regex matching string (^-?\d+[.]\d{1}), etc. None of these appear to match and I’m kind of at a loss as to why this isn’t working. I have tried using String.Format(testStr,“0.00”) to use the built-in formatting for this but this doesn’t work in UiPath no matter what I tried.

Any help with either option would help. Thanks!


welcome to the forum

have a look on these statements
String.Format("{0:0.00}", 1/3) returning 0.33
String.Format("{0:0.00}", CDbl("-1.2")) returning -1.20


I suppose String.Format is better way as @ppr suggests, but if you want to use Regex for some reason the following expression helps you.



The second option worked for me for the most part. I’m getting some incorrect conversions on data though (converting from 166758.06 to 166758.10).

I did a test at my end, but cannot confirm. It was formatted as expected

Can you recheck at your end?

Well, it is working in every case, now. Maybe I hallucinated last night? Thanks for the support!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.