Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comma and (decimal) point: Do they need different handling?

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.

like image 905
Dante1986 Avatar asked Jan 16 '12 19:01

Dante1986


People also ask

What is the difference between a comma and decimal point?

United States (U.S.) currency is formatted with a decimal point (.) as a separator between the dollars and cents. Some countries use a comma (,) instead of a decimal to indicate that separation.

Why do people use commas instead of decimal points?

Leibniz was an influential mathematician, and the dot as a multiplication sign became widespread in Europe. But this solution created another problem: The dot as a multiplication sign could be confused with the decimal point. So, European mathematicians started to use a comma to separate decimals.


3 Answers

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.)

like image 148
Greg Hewgill Avatar answered Oct 02 '22 08:10

Greg Hewgill


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"
like image 20
Ahmet Kakıcı Avatar answered Oct 02 '22 08:10

Ahmet Kakıcı


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

like image 41
Chris Shain Avatar answered Oct 02 '22 09:10

Chris Shain