How do you convert a string value "123.45" to a decimal data type

  • Thread starter Thread starter Guest
  • Start date Start date
Use either System.Convert.ToDecimal or decimal.Parse method. Make sure that
the decimal separator for the current culture is the same as the one you're
trying to parse - otherwise you might get a FormatException (parse method)
or an unpredicted result in some cases.

Here is the example with the Parse method :

string s = "123.45";
NumberFormatInfo nfi = new NumberFormatInfo();
nfi.CurrencyDecimalSeparator = ".";
decimal dec = decimal.Parse(s, nfi);


Hope that helps,
Branimir
 
Back
Top