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?
@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?
Dim str=“1.20200”
str=str.TrimEnd(New String({“0”, “.”}))
Output: 1.202
It’s working for me
Can you try putting character c next to the double quotes…
Sorry that I can’t check in Uipath now
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.
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
@ClaytonM when I did the assign activity with prodCostCompare=CDbl(prodCostCompare.Trim).ToString
I get this error
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.