简体   繁体   English

根据国家/地区更改货币格式 select

[英]Change currency format based on country select

I have a dropdownlist of all countries.我有一个所有国家的下拉列表。 I want to be able to display a certain amount in currency format based on the country selected by user.我希望能够根据用户选择的国家/地区以货币格式显示一定数量。 Currently I'm just using amount.ToString("C") and it just displays the dollar sign.目前我只是在使用amount.ToString("C")它只显示美元符号。 But what the user selects a european country then it should be able to display in Euro format?但是用户选择一个欧洲国家那么它应该能够以欧元格式显示吗? Is there any way to achieve this in c# on the dropdownlist selectedindexchanged event perhaps?有没有办法在 c# 中的下拉列表 selectedindexchanged 事件中实现这一点?

Help would be much appreciated.帮助将不胜感激。 Thanks.谢谢。

Adapted from Formatting Numeric Data for a Specific Culture :改编自Formatting Numeric Data for a specific Culture

CultureInfo info;
if (country == "Poland")
{
  info = new CultureInfo("pl-PL");
}
else if (country == "England")
{
  info = new CultureInfo("en-GB");
}
else
{
  info = new CultureInfo("en-US");
}
Console.WriteLine((1.23).ToString("c", info));
decimal price = 123.45m;
int discount = 50;
Console.WriteLine($"Price: {price:C} (Save {discount:C})");

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

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