Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Decimals – I try to use "." gives error in one place I try "," gives in another place

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

//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 "."

>Solution :

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"));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading