I'm trying to convert a string to a double value but it's not returning me what I expect...
double dbl;
Double.TryParse("20.0", out dbl);
That piece of code is returning 200.0 (instead of 20.0) as a double value. Any idea why?
We can convert String to double in java using Double. parseDouble() method.
In C++, the stod() function performs a string to double conversion.
Use float() method or decimal() method to convert string to double in Python. Conversion of string to double is the same as the conversion of string to float.
String value can be converted to double using Convert. ToDouble() or Double. Parse() method. These methods take string representation of a number as input and return its equivalent double-precision floating-point number.
You should pass InvariantCulture
to the method.
The reason behind this is that your regional settings probably set .
as separator character and not decimal point.
double.TryParse("20.0", NumberStyles.Any,
CultureInfo.InvariantCulture, out x);
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