Quantcast
Channel: Installation and Setup
Viewing all articles
Browse latest Browse all 631

Convert.ToSingle("0,5", CultureInfo.CurrentUICulture) for culture "de-CH" works differently on my Dev. machines

$
0
0

Hi all

I have two development machines, both have Windows 8.1 installed. On one of theme the operating System is installed in English on the other it is installed in German. On both machines I have set the Region in System Settings to "German (Switzerland)" and assuming the other language specific Settings, especially the one for the Decimal Symbol, would then be set identically (in this case to a comma).

Now in my ASP.NET MVC 4 Application I set CurrentCulture and CurrentUICulture to "de-CH" in the Application_Start Event.

When I then execute the following line of code it works on the machine where the os is installed in English, but doesn't work on the other machine:
string attemptedValue = Convert.ToSingle("0,5", CultureInfo.CurrentUICulture); // Notice the comma in the string.

Exception Message is like: "Input String was not in correct Format." When I chage the above line of code to:
string attemptedValue = Convert.ToSingle("0.5", CultureInfo.CurrentUICulture); // Notice the dot in the string.

then the opposite happens. It works on the machine where the os is in German installed, but doesn't work on the machine where the os is installend in English.

So my question:
How should I convert a string, representing an decimal value on the Server depending on the culture? I thought this is done in the way I try to implement it?

Thanks for help
Aedu


Viewing all articles
Browse latest Browse all 631

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>