Round of decimals in string to 2 places

Hi team ,

I have “211.3424324” stored in a string variable.
How do I make it 211.34?

I do not want to convert it to double or any other datatype.

Kindly help.

Regards,
G

Hello,

I think you can check this link https://forum.uipath.com/t/keep-decimal-places-at-2-decimals/116230

Can you help me with the above example which I have provided and help me with an assign query please

Can you try : String.Format(“0.##”, YourString) ?

Hi,

How about the following?

image

System.Text.RegularExpressions.Regex.Match(yourString,"\d+\.\d{2}").Value

Regards,

1 Like

thank you !

1 Like

It is giving ## in the output
Thank you for your prompt response

Hi,

FYI, please note that the expression will round down the value.

Regards,

Hi @Yoichi it is giving null value for “4234.2”.
Similarly for integers also.
I want this value to be fetched also.

If it is 4234 or 4234.2.
It should return the same value and if its

4234.234 then it should be 4234.23

Regards,
G

HI,

Can you try the following?

System.Text.RegularExpressions.Regex.Match(yourString,"\d+\.\d{1,2}").Value

Regards,

HI @gokul1904

Try this expression

System.Text.RegularExpressions.Regex.Match(YourString,"\d+\.\d{1,2}").Tostring

Regards
Gokul

Hi,

If you also want to handle integer such as just “212”, the following will work.

System.Text.RegularExpressions.Regex.Match(yourString,"\d+\.?\d{0,2}").Value

Regards,

1 Like

Perfect! Thanks alot again!

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