String to Integer

@arivu96
I’d advise against using integers to store monetary values, you’ll lose precision.

@ClaytonM
Decimal should be used for monetary values. Double is close, but it loses precision with large/very small numbers (and with multiplications it’s not that hard to get there).

For both I’d say using string.replace to get rid of currency number is not the best approach. It’s also safer to use .Parse (or .TryParse) instead of convert, as it allows specifying culture and number styles.

For example:
(requires System.Globalization namespace to be imported)
decimalFromDollars = Decimal.Parse("$100", NumberStyles.Currency, CultureInfo.CreateSpecificCulture("en-US"));
decimalFromEuro = Decimal.Parse("€100", NumberStyles.Currency, CultureInfo.CreateSpecificCulture("de-DE"));
decimalFromPLN = Decimal.Parse("100 zł", NumberStyles.Currency, CultureInfo.CreateSpecificCulture("pl-PL"))

3 Likes