I am trying to parse string \"0.0000\" with double.TryParse()
but I have no idea why would it return false in this particular example. When I pass integer-like stri
TryParse
uses the current culture by default. And if your current culture uses a decimal seperator different from .
, it can't parse 0.0000
as you intend. So you need to pass in CultureInfo.InvariantCulture
.
var numberStyle = NumberStyles.AllowLeadingWhite |
NumberStyles.AllowTrailingWhite |
NumberStyles.AllowLeadingSign |
NumberStyles.AllowDecimalPoint |
NumberStyles.AllowThousands |
NumberStyles.AllowExponent;//Choose what you need
double.TryParse( "0.0000", numberStyle, CultureInfo.InvariantCulture, out myVar)