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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With