开发者

Convert string representation of numbers less than 1 to double

Convert.ToDouble Method (String) converts the specified String representation of a number to an equivalent double-precisi开发者_StackOverflow社区on floating point number.

I have this line of code: double d = Convert.ToDouble("0.3");

and it gives me 3.0 instead of 0.3. For numbers greater than 1 it works as expected. Why?


Most likely a locale problem. There are cultures where . is not the decimal separator.

Try double.Parse("0.3",CultureInfo.InvariantCulture)


Try this:

NumberFormatInfo provider = new NumberFormatInfo();
provider.NumberDecimalSeparator = ".";
double d = Convert.ToDouble("0.3", provider);


What are the current Culture settings? It's probably because in the culture settings you are using the '.' is not the decimal delimiter!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜