Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double.Parse not giving correct result

I'm trying this in two application; a console application and a web application.

In the console app when I try Double.Parse("0.5") it gives 0.5 or Double.Parse(".5") gives 0.5

But in the web application Double.Parse("0.5") gives 5.0 and Double.Parse(".5") gives exception

Input string was not in a correct format.

Can any one tell how can resolve the issue in web app?

like image 207
MNVR Avatar asked Mar 20 '12 13:03

MNVR


1 Answers

You should provide culture information otherwise it uses the culture info from the currently running thread. Try this instead:

CultureInfo cultureInfo = CultureInfo.InvariantCulture; // or whatever you prefer
double result = double.Parse(".5", cultureInfo);
like image 132
Mark Byers Avatar answered Oct 13 '22 14:10

Mark Byers