0

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?

1 Answers1

1

You can use the string function ,TrimEnd(char) and .TrimStart(char)

This example will trim any trailing zeros and the dollar sign and, if your string has started as "12.00" it will also remove the decimal point, but only if there are no digits after the decimal point.

Dim st As String = "$12.50" 
st = st.TrimEnd("0"c).TrimEnd("."c).TrimStart("$"c)

Although as other people have commented, you would be much better parsing it to Decimal type as early as posible in your code. Trying to work with numbers stored as strings is a recipe for problems.

David Wilson
  • 4,369
  • 3
  • 18
  • 31