当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - IIS 7 - determine decimal symbol

问题描述:

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.

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: