views:

164

answers:

1

My IIS 7 server uses a C#.NET codefile to read from an MS SQL database (on another machine) and presents it on the web. I made a similar posting before, but the problem has resurfaced and I've not been able to fix it.

In this regard I've had a problem with my Norwegian Windows Server running IIS 7. It reads the columns from a database which returns some coordinates with decimals. In the database I managed to change the decimal symbol from the Norwegian default (comma) to periods, by changing the windows settings.

I did the same thing on the Windows 2008 server running IIS 7, but it still translates the periods back to commas. I need it to be periods. I even changed the code to convert the rows to strings and then replace all commas with periods, but it still doesn't work.

Any help here would be greatly appreciated.

+1  A: 

Hi

First things first - I'm assuming you mean something like ASP.NET Web Forms, right?

If so, then in the web.config, have you set:

<globalization culture="auto"/>

If you've done that, and you're getting some problems still, it might be that the language settings as defined in the browser are wrong. Check those.

You can omit the above web.config line if you don't care about detecting the user's locale, and always displaying decimals according to their preferences.

You can change that line to the following:

<globalization culture="NN-NO"/>

... to force your web application to always use Norwegian Bokmål (Norway) (NN-NO) as it's default culture, which should force the decimals to display the way that you need.

As an alternative, you can choose to format any decimals on screen according to a particular format, using NumberFormatInfo, as in my example below:

NumberFormatInfo ni = Globalization.CultureInfo.GetCultureInfo("NB-NO").NumberFormat; 
Decimal.ToString("c", ni); 

Hope this helps,

Richard.

Richard
@Richard, Thanks for enlightening me, I did not know about this kind of functionality. I am using the ASP.NET MVC2 framework. I am seeing that when I put things on the IIS server it gives me the comma decimal, but when I test it locally using the built in debugger in Visual Studio, I get period decimals.I don't understand why, it seems there's something with the IIS server, not the browser.
cc0
@cc0 - the localisation/globalisation features can seem a bit confusing but in my experience it's usually the browser settings which are wrong, when .NET is set to detect them on the server. Double-check the web.config on your local machine, and on your live environment. Add the line I mentioned and experiment with the settings. Don't forget, if you don't own or control the web server then it is possible that your host has some settings configured in the machine.config that are overriding the default behavior. Try this first, then let me know how you get on.
Richard
@Richard - will do.
cc0
@Richard - That's it. Everything works now! I forced the globalization culture to EN-US and now it spits out the right decimals. Awesome. Thank you, sir!
cc0
@cc0 glad to have been of help :)
Richard