Remove 0 from end of String

I am saving a scraped number as a string (ex: $12.50) and comparing it to an excel table that has numbers as (ex:12.5). I was using: Replace(“0”, “”) to get rid of the zeroes but it removes zeroes in a number such as .034,

How do I remove the dollar sign from the front and also remove zeroes that might be on the end of the string?

Thanks!

@Mikej1815 ,

Let’s take the value in string str…

  1. str=str.remove(str.length-1)
  2. str=str.substring(0,str.length-1)

Actually , you have many :smiley:

Let me know if any issue.

Regards,
SP

1 Like

@SantoshPothina Thanks. I forgot to mention that some numbers are like: 0.858, so wouldn’t str=str.remove(str.length-1) remove the 8 from the end of the string. Is there a way around this?

Cheers

Ok understood, then you can achieve this by using TrimEnd method…

str.TrimEnd(New String({“0”, “.”}))

Let me know if any issue.

Regards,
SP

1 Like

@SantoshPothina

I used an assign activity prodCostCompare = prodCostCompare.TrimEnd(prodCostCompare({“0”, “.”}))

Got the error: image

Variable shows as a string in the variable manager

Dim str=“1.20200”
str=str.TrimEnd(New String({“0”, “.”}))
Output: 1.202
It’s working for me :blush:
Can you try putting character c next to the double quotes…
Sorry that I can’t check in Uipath now :frowning:

Regards,
SP

Hey @Mikej1815

Honestly, the best way to compare numbers is to compare them as numbers.
So to do that is you just need to convert both sides to a Double type so it has decimals. Doing this will round both sides.

Example:

CDbl(str1.Trim) = CDbl(str2.Trim)
or
Convert.ToDouble(str1.Trim) = Convert.ToDouble(str2.Trim)

Occasionally, you will get a string that is not a number or an empty string. So you will need to also make sure it’s a number.

If(IsNumeric(str1.Trim) And IsNumeric(str2.Trim), CDbl(str1.Trim) = CDbl(str2.Trim), False)

If the $ sign doesn’t convert, then use the .Replace(“$”,“”), because I can’t remember if that sign gets seen as a number or not.

I hope this helps.

Regards.

4 Likes

@ClaytonM

Hey, I am getting this error image

prodCostCompare is a String type variable, so you need to either change it to a System.Double type for the left side, or change the right side to have .ToString, like CDbl(prodCostCompare.Trim).ToString

2 Likes

You can use
Yourstring(yourstring.length-1)

@ClaytonM when I did the assign activity with prodCostCompare=CDbl(prodCostCompare.Trim).ToString

I get this error Capture

Also, if I just try to compare them in the decision block: Cdbl(prodCost.Trim)=Cdbl(prodCostCompare.Trim)
I get the error: Conversion from string "$0.022" to type ‘Double’ is not valid.",

This conversion is getting failed because you have $ in your string.
Remove or replace dollar from the string and then convert both numbers to double and compare.

1 Like

I am having 1,234.00 i want to delet decimal nd 2 zeros. Can any1 help

Hi @Darshhan

You can use following formula to get to 1234:
System.Text.RegularExpressions.Regex.Replace(yourStringVariable,"\.00$","").ToString.Replace(",","")

This will only work if the .00 is at the end of the line.

Thank you and What if there is a comma instead of .

I think just i need to replace . With comma right…??

I think in this case this regex will work:
System.Text.RegularExpressions.Regex.Replace(yourStringVariable,".00$","").ToString.Replace(",","")

Now, instead of finding a dot, two zeros and the end of line character, it finds a single any character, two zeros and end of line :slight_smile:

1 Like

Thank you it works

1 Like