5

Just something that i was wondering about. In Europe the comma us mostly used for decimals (like 20,001) but outside Europe the point is mostly used (like 20.001) How does c# handle this ? In case of a application that will be used by Europe and non-Europe people, do you need to worry about the above when programming ?

Just curious about this.

dbc
  • 104,963
  • 20
  • 228
  • 340
Dante1986
  • 58,291
  • 13
  • 39
  • 54

5 Answers5

13

As far as the programming language is concerned, the decimal point separator is always ., and the punctuation used to separate function arguments is always ,. Changing that based on the spoken language of the programmer would be too confusing.

For the user interface, there are formatting functions in the CultureInfo class that can produce a floating point number representation that uses the decimal point separator and thousands separator of your choice. (Or, for cultures that group digits of a number differently than in triplets, the formatting functions can handle that too.)

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • Ahaa yes that was exactly what i meant, what happens when the user uses point or comma in (for example) the textbox that in the code is used for inputvalue. But now is see, the programmer can set some separator so the code can understand, (and thus get the same input regardless of the . or ,) thanx for explenation – Dante1986 Jan 16 '12 at 19:25
  • It's interesting that the entire programming language industry is US-centric -- there isn't a single language (that I know of) where a native European programmer could write three-and-a-half as 3,5 in his code. – Ross Presser May 23 '13 at 20:36
7

CultureInfo handles that situation.

Take a look at this

// format float to string
float num = 1.5f;
string str = num.ToString(CultureInfo.InvariantCulture.NumberFormat);        // "1.5"
string str = num.ToString(CultureInfo.GetCultureInfo("de-DE").NumberFormat); // "1,5"
Ahmet Kakıcı
  • 6,294
  • 4
  • 37
  • 49
3

Yes, c# (and really, the whole .NET framework) have the concept of Cultures for this purpose:

http://msdn.microsoft.com/en-us/library/bz9tc508.aspx

and

http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo(v=VS.100).aspx

Chris Shain
  • 50,833
  • 6
  • 93
  • 125
0

You should use CultureInfo Class to handle it. Just read and write with correct formatter.

Alex Dn
  • 5,465
  • 7
  • 41
  • 79
0

That depends on what exactly you do... .NET is usually aware of the current settings of the machine/OS and uses those...

You should look into this and see whether any of it is relevant in your case...

Yahia
  • 69,653
  • 9
  • 115
  • 144