2

In English-US, the decimal separator symbol is "." So if I want to write the result of 100 + 25/100, it will be 100.25 (obviously).

How will I write it in a constant in Visual Studio if I'm a french developer living in France? In France they use a comma (",") as a decimal seperator.

Will I write

const double x = 100.25

or

const double x = 100,25

Thank you

alex
  • 133
  • 1
  • 6

3 Answers3

2

You write programs in C#, not in English. Use syntax of C#.

const float x = 100.25

When you show some information for non-Englsih user you can format it in appropriate view.

For ex.:

MessageBox.Show(x.ToString().Replace(".", ",")); // or some special format functions
Roman
  • 502
  • 7
  • 17
  • 3
    I think it is better to show in example `CultureInfo` usage. It will be more useful – Fedor Apr 06 '14 at 16:03
  • 1
    also, you could not store float values in `int` variable – Fedor Apr 06 '14 at 16:04
  • @Fyodor Ahaha, Yes, you are right. I have not even noticed this "little" error with int/float type :) Upd. And thanks for "CultureInfo", I didn't know about it before. – Roman Apr 06 '14 at 16:08
  • 1
    SO is a Q&A site and people expect to read correct and self-contained answers to the question, so if you understand how to improve/correct your answer and able to do it, please do it every time. – Fedor Apr 07 '14 at 18:46
1

The first. There are no cultural variants of C# compiler, the code is compilable by any compiler. Besides that, , has some different usages in C# that would be incompatible, e.g. separating entries in new List:

var data = new List<double> { 1.0, 2.0, 3.0 };
Tomas Pastircak
  • 2,867
  • 16
  • 28
0

They will have to write 100.25 too. The source code itself is independent of culture. If this wasn't the case, you'd need some way to specify the culture to the compiler.

Programmers could declare the values as strings and then use double.Parse with an appropriate format provider, but that would be a runtime conversion and an inefficient way to declare values known at compile time.

Matthew Strawbridge
  • 19,940
  • 10
  • 72
  • 93