简体   繁体   English

如何使用当前文化信息获取货币格式并验证该货币

[英]How to get format of currency using current culture information and validate that currency

I have requirement where i have currency code and using that code i am finding the current culture of that currency and also symbol of that currency.我要求在哪里有货币代码,并使用该代码找到该货币的当前文化以及该货币的符号。

在此处输入图片说明 Here I have the ability to change the currency ISO code and if user changes the code according to that i am changing the currency symbol.在这里,我可以更改货币 ISO 代码,如果用户根据我正在更改的货币符号更改代码。

Now i want to find the format of that culture using currency ISO code.Which format that culture uses for currency.How can i find that?现在我想使用货币 ISO 代码找到该文化的格式。该文化用于货币的格式。我怎样才能找到它?

And using that format i want to do the validation of currency.If user enter currency in wrong format then i want to give the validation how can i do that?并且使用该格式我想进行货币验证。如果用户以错误的格式输入货币,那么我想进行验证我该怎么做?

The decimal type, which is good for a currency, has the TryParse method that accepts the culture. decimal类型适用于货币,具有接受文化的TryParse方法。

bool IsValidCurrency(string s, string tla, out value)
{
  var culture = CultureInfo
   .GetCultures(CultureTypes.AllCultures)
   .Where(c => c.ISOCurrencySymbol == tla)
   .First();
  return decimal.TryParse(s, NumberStyles.Any, culture, out value)
}

Where s is the text representation of the currency value and tla is the ISO three letter abbreviation of the currency.其中s是货币价值的文本表示, tla是货币的 ISO 三字母缩写。

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

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