简体   繁体   English

货币文化信息

[英]Currency CultureInfo

I need to display currency in a culture specific way we are currently supporting only english speaking countires but that might expand to another countries. 我需要以一种特定于文化的方式显示货币,我们目前仅支持说英语的国家,但可能会扩展到其他国家。 We are implementing this quickly so I need a way of displaying a universal currency format for the time being until I can implement a culture specific. 我们正在快速实施,因此我需要一种方法来暂时显示通用货币格式,直到可以实施特定文化。

Does anyone know the best way to do this? 有谁知道最好的方法吗?

The Executing Thread has a CultureInfo attribute attached to it for example "en-GB" which is "English-Great Britain" or "cy-GB", for "Welsh- Great Britian"(The First 2 characters represent the language the Second 2 the country). 执行线程具有附加的CultureInfo属性,例如,“ Welsh-Great Britian”的“ en-GB”是“ English-Great Britain”或“ cy-GB”(前2个字符代表第二个语言国家)。 So when you are calling 所以当你打电话时

double amount = 2.00;
amount.ToString("C")//Without a culture argument you are 
                    //actually passing the CultureInfo 

So to add specific CultureInfo to a string all you have to do is supply a new CultureInfo and add it as a second argument in ToString like so: 因此,要将特定的CultureInfo添加到字符串中,只需提供一个新的CultureInfo并将其作为ToString中的第二个参数添加,如下所示:

CultureInfo ci = new CultureInfo("en-GB");
amount.ToString("C", ci);

Add the following line to the Web.config to change it application wide 将以下行添加到Web.config中以在整个应用程序中进行更改

<globalization uiCulture="en" culture="en-GB" />

OR the Following line if you would like it as a Per Page Basis 如果您希望将其作为每页基础,则使用下一行

<%@ Page UICulture="en" Culture="en-GB" %>

OR Change the Culture on the Executing Thread 或更改执行线程上的区域性

CultureInfo ci = new CultureInfo("en-GB");
System.Threading.Thread.CurrentThread.CurrentCulture = ci;

The international way of display currency is (U+00A4)(As Referenced CLR Via C# as I haven't seen it anywhere else) which can be displayed using . 显示货币的国际方式是(U + 00A4)(正如我在其他地方没有看到的那样,通过C#引用CLR),可以使用进行显示。 ToString("C", CultureInfo.InvariantCulture) which displays a little star thing which I dont think anyone will recognize. ToString("C", CultureInfo.InvariantCulture)显示了一个小小的星星,我认为没有人会认出。

Also, please remember that none of this is getting around the currency conversion problem, unless everything that needs to be displayed converts straight across to another currency value for value. 另外,请记住,所有这些都不能解决货币转换问题,除非需要显示的所有内容都直接转换为另一种货币价值。 You would be better off just display in US dollars Or UK Pounds until you can work out the best way to localize your application. 最好只显示美元或英镑,直到找到可以本地化应用程序的最佳方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM