Its all about double, float numbers and seperator. So my problem is: I always get double value with dot seperator. If I convert it to string I get comma. If I change it back to double it gets dot again. Add some code here:

    data = Convert.ToDouble(read.ReadSingle()); // converts to -70.00
    Conv = Convert.ToString(data); // converts to -70,00 string
    laikinas[k, m] = double.Parse(Conv);  // and in array I'll get 70.00. 

I'am sure with region settings is everything good. I can see CurrentCulture as it must be.

BTW I changed region settings while I was a half made off project.

有帮助吗?

解决方案

A double has neither a dot nor a comma; it's stored in some internal representation. When you look at it, for example, through the Visual Studio debugger, you see some string representation of it (the one which Visual Studio chooses to use). This string representation is irrelevant, it is only shown for debug purposes.

If you convert your double into a string, you can choose which number format is used:

  • Convert.ToString(Double) is equivalent to Double.ToString(), which uses a decimal separator based on your current culture -- hence, you get the comma (on your system) when using Convert.ToString.

  • If you use another method for conversion, for example, Double.ToString(IFormatProvider), you can specify the culture settings you want to use as a parameter. For example, myDouble.ToString(CultureInfo.InvariantCulture) will always use a dot as the decimal separator, independent of the user's culture settings.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top