Home > Enterprise >  Decimals - I try to use "." gives error in one place I try "," gives in another
Decimals - I try to use "." gives error in one place I try "," gives in another

Time:12-07

I insert for example 12.45 gives me error here:

//Input string was not in a correct format

deposit = decimal.Parse(Console.ReadLine());

If I insert 12,45 gives me error here:

//Incorrect syntax near ','

var reader = cmd.ExecuteReader();

Here is already after the part where it gives error on top, and the value already works up there, but down here not

Here shows that up there works, but I insated with "," but appears with "."

CodePudding user response:

If you want to be able to correctly parse a number using a comma "12,45" instead of a period "12.45" there are a number of overloads that will allow you to specify the decimal separator in different ways:

For example, using German culture info (I don't know what culture you're using)

var deposit = decimal.Parse("12,45", new CultureInfo("de-DE"));
  • Related