0

When I apply toString() on a number of type double, I get the string with . as the decimal separator. In one of my projects only, I get , as the decimal separator.

I have not changed CultureInfo data. My CurrentCulture is el-GR in all my projects which is the default system Culture. el-GR uses , as the decimal separator but I have changed this value through Windows Regional Settings to . which is reflected correctly to all my projects except the one in question.

The only difference I can tell is that it is a Web Site and not a usual Visual Studio Project. I do not know if this forces Visual Studio NOT to take into account the local computer NumberFormat exceptions and if/how this can be changed.

Daniel Corzo
  • 1,055
  • 2
  • 19
  • 32
Saloom
  • 163
  • 10
  • I can't tell you why this is happening in this particular case, but you can always pass a specific CultureInfo as a parameter to `ToString` and most `Parse` methods to ensure you always work with the same culture. You could also check if `CultureInfo.CurrentCulture` and `CultureInfo.CurrentUICulture` are identical (e.g. by showing both on a special page). – Manfred Radlwimmer Sep 28 '17 at 07:14
  • I'll randomly guess that the misbehaving project targets an old .NET version. – Hans Passant Sep 28 '17 at 07:21
  • @ManfredRadlwimmer I would prefer to avoid specifying a CultureInfo as a parameter. I have already made the test you suggest and CurrentCulture is different than CurrentUICulture. But so is in all my other projects. Do you know which of the 2 the framework uses by default? – Saloom Sep 28 '17 at 10:25
  • @HansPassant It targets version 4.5.2 – Saloom Sep 28 '17 at 10:26
  • en-GB instead of en-GR? GR stands for greece, if I'm not mistaken – D Ie Sep 28 '17 at 12:24
  • @DIe My mistake, it is el-GR. – Saloom Sep 28 '17 at 14:11
  • 1
    the CultureInfo your program use, if you don't explicitly set it somehow in code, is related to Regional Settings of **current user**. When running a web project, very likely current user is not you, the one logged in in the computer, but a built-in user IIS uses. see [this question](https://stackoverflow.com/questions/1240373/how-do-i-get-the-current-username-in-net-using-c) and display somehow current user – Gian Paolo Sep 28 '17 at 15:22
  • @GianPaolo That is very true indeed! It solves the mystery. How can I mark this comment as the correct answer? – Saloom Sep 28 '17 at 16:48
  • added my comment as answer @Saloom – Gian Paolo Sep 28 '17 at 18:35

1 Answers1

1

The CultureInfo your program use, if you don't explicitly set it somehow in code, is related to Regional Settings of current user.

When running a web project, very likely current user is not you, the one logged in in the computer, but a built-in user IIS uses. see this question and display somehow current user to find out if your problem is actually related to this.

To change regional settings for your (.Net & IIS hosted) web application, you can use different method: web.config of your application, web.config of the whole server, settings for IIS, or even tweak the registry.

Have a look at this thread (and also linked threads you find in the left column) for methods you can use.

Gian Paolo
  • 4,161
  • 4
  • 16
  • 34