That will not work.
Here is a fix, put this code in the Invoke Code:
Try
' Try converting the input string using the German (de-DE) culture
inputString = CInt(Convert.ToDecimal(inputString.Replace("$", ""), System.Globalization.CultureInfo.GetCultureInfo("de-DE"))).ToString()
Catch ex As Exception
' If an exception occurs, check if it's the exception case (last comma before the last two digits)
If inputString.LastIndexOf(",") = inputString.Length - 3 Then
' Replace the last comma with a decimal
inputString = inputString.Substring(0, inputString.LastIndexOf(",")) & "." & inputString.Substring(inputString.LastIndexOf(",") + 1)
' Try the conversion again with the corrected input
inputString = CInt(Convert.ToDecimal(inputString.Replace("$", ""), System.Globalization.CultureInfo.GetCultureInfo("en-US"))).ToString()
Else
' If the exception is not related to the specific case, rethrow the exception
Throw
End If
End Try
Explanation of the Logic:
- Try to convert German numeral to Decimal and then convert to Int and then into String.
- Catch Exception (invalid format Price):
If inputString.LastIndexOf(“,”) = inputString.Length - 3, (comma is the decimal point) then:
- Replace that comma with a Dot (making it US format)
- Convert US format to Decimal, then to Int and then into String
Else,
- Throw Exception
Output:
