Insert a character in a string

I want to check a string if it ends with a single zero (e.g. 123.0) and if does I want to add another zero “123.00” but if doesn’t (e.g. 10500.25) it will not do anything to that string and will just remain as 10500.25.

I’m thinking this will be a combination of If and Regex.

How can I implement this logic?

Any kind of help would be appreciated.

Regards,
Anthony Jr.

Hi,

Can you try the following expression?

Double.Parse(yourString).ToString("#.00")

Regards,

2 Likes

HI @anthonyjr

You can trey with Regex expression

System.Text.RegularExpressions.Regex.Ismatch(YourString,"0$")

In the Then

System.Text.RegularExpressions.Regex.Replace(YourString,"0$","00").Tostring

image

Regards
Gokul

1 Like

It’s working perfectly. Thank you so much for your expertise sir @Yoichi

Best Regards,
Anthony Jr.

1 Like

HI @anthonyjr

Checkout this

if(Split(str,".")(1).ToString.Length=2,str,Double.Parse(str).ToString("#.00"))

image
image

Regards
Sudharsan

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