2

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.

Bibhu
  • 4,053
  • 4
  • 33
  • 63
Dovydas
  • 99
  • 2
  • 8

1 Answers1

11

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.

Heinzi
  • 167,459
  • 57
  • 363
  • 519
  • Ok, thanks didnt known it. But what about MS.Graphs maybe its same issue. Because Biggest problem is I sent these numbers to MS.Chart. and get dots too. So it maybe choose by it self how to represent number, and show dot too. Maybe there is any work around to get commas? Thank you. I feel better knowing my code is not messed up :) – Dovydas Jan 10 '12 at 07:03
  • @Dovydas: This might be an issue of MS.Graphs not respecting your culture settings when converting your doubles into strings. I suggest starting a new question about this, where you (a) mention that Convert.ToString correctly shows a comma (to prove that your regional settings are correct) and (b) give a *short* code example that demonstrates how you are using MS.Charts and that can be used to reproduce the problem. – Heinzi Jan 10 '12 at 07:13