如何从CultureInformation获取格式化货币 [英] How to get formatted Currency-from CultureInformation

查看:91
本文介绍了如何从CultureInformation获取格式化货币的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用System.Globalization.CultureInfo。



通过使用文化信息我访问NumberFormatInfo类。



这段代码中使用了这个代码片段。



< pre lang =cs> public static List< CultureInfo> CultureInfoList = new List< CultureInfo>((CultureInfo [])CultureInfo.GetCultures(CultureTypes.SpecificCultures));

public static NumberFormatInfo CurrentNumberFormat {获得; set ; }

public static RegionInfo CurrentRegionInfo {获得; set ; }

public static string GetClinicFormattedCurrency( double _amounttobeFormatted)
{
try
{
var _cultureInfo = CultureInfoList.FirstOrDefault(s = > s.Name == en-US);
CurrentRegionInfo = new RegionInfo(_cultureInfo.LCID);

CurrentNumberFormat = _cultureInfo.NumberFormat;

if (CurrentNumberFormat!= null
return _amounttobeFormatted.ToString( c,CurrentNumberFormat) ;
else return _amounttobeFormatted.ToString();
}
catch (例外)
{
return _amounttobeFormatted.ToString();
}
}





由于这个fomatting自动处理舍入,逗号,负数等,很好。



但问题是这种格式化为我提供1000美元作为1000美元,但我想要美元而不是美元。



USD在CurrentRegionInfo.ISOCurrencySymbol中可用。





我还想根据reoprt / rdlc中的文化格式化数量为好吧。



为此我正在使用这个表达式:



解决方案适用于C#代码和UI显示的东西,但当我想生成报告时,货币按照标准逻辑格式化,因为它使用系统文化。



我用于格式化的表达式报告如下:



**变量ClinicLanguage值以en-US提供



 = CDbl(参数!Payment.Value).ToString(C)
= IIF(String.IsNullOrEmp ty(参数!ClinicLanguage.Value),参数!Payment.Value,CDbl(参数!Payment.Value).ToString(C))







请建议。



谢谢&此致,

Abhishek

解决方案

1,000但我想要美元代替






美元在CurrentRegionInfo.ISOCurrencySymbol中可用。





我也想格式化reoprt / rdlc中基于文化的金额。



为此我正在使用这个表达式:



该解决方案适用于C#代码和UI显示,但是当我想生成报告时,货币按标准逻辑格式化,因为它使用系统文化。



我在报告中用于格式化的表达式如下:



**变量ClinicLanguage值以en-US提供



 = CDbl(参数!Payment.Value).ToString(C)
= IIF(String.IsNullOrEmpty(Parameters!ClinicLanguage.Value),参数!Payment.Value,CDbl(参数!Payment.Value).ToString(C))







请建议。



谢谢&此致,

Abhishek


您好Abhishek,



如果您不需要更改它然后以编程方式:



您可以做的是更改Windows本身的区域设置,然后在您的程序中它也会更改。



控制面板/区域/格式选项卡 - 其他设置/货币选项卡 - 货币符号下拉列表(从

更改

Hi,

I'm using System.Globalization.CultureInfo for the purpose.

By using Culture info I access NumberFormatInfo Class.

Which is used in this code snippet.

public static List<CultureInfo> CultureInfoList = new List<CultureInfo>((CultureInfo[])CultureInfo.GetCultures(CultureTypes.SpecificCultures));

        public static NumberFormatInfo CurrentNumberFormat { get; set; }

        public static RegionInfo CurrentRegionInfo { get; set; }

        public static string GetClinicFormattedCurrency(double _amounttobeFormatted)
        {
            try
            {
                var _cultureInfo = CultureInfoList.FirstOrDefault(s => s.Name == "en-US");
                CurrentRegionInfo = new RegionInfo(_cultureInfo.LCID);

                CurrentNumberFormat = _cultureInfo.NumberFormat;

                if (CurrentNumberFormat != null)
                    return _amounttobeFormatted.ToString("c", CurrentNumberFormat);
                else return _amounttobeFormatted.ToString();
            }
            catch (Exception)
            {
                return _amounttobeFormatted.ToString();
            }
        }



Since this fomatting automatically handles rounding, comma-places, negative amounts, etc, Its great.

But the problem is this formatting provides me 1000 as $1,000 but I want USD instead of $.

USD is available in CurrentRegionInfo.ISOCurrencySymbol.


I also want to format the amount based on culture in reoprt/rdlc as well.

for that purpose i'm using this expression:

The solution worked for C# codes and UI display things, but when I want to generate the reports the currency get formatted as per standard logic since it uses system culture.

the expression i use for formatting in report is as follows:

**variable ClinicLanguage value supplied as "en-US"

=CDbl(Parameters!Payment.Value).ToString("C")
=IIF(String.IsNullOrEmpty(Parameters!ClinicLanguage.Value),Parameters!Payment.Value,CDbl(Parameters!Payment.Value).ToString("C"))




Kindly suggest.

Thanks & Regards,
Abhishek

解决方案

1,000 but I want USD instead of


.

USD is available in CurrentRegionInfo.ISOCurrencySymbol.


I also want to format the amount based on culture in reoprt/rdlc as well.

for that purpose i'm using this expression:

The solution worked for C# codes and UI display things, but when I want to generate the reports the currency get formatted as per standard logic since it uses system culture.

the expression i use for formatting in report is as follows:

**variable ClinicLanguage value supplied as "en-US"

=CDbl(Parameters!Payment.Value).ToString("C")
=IIF(String.IsNullOrEmpty(Parameters!ClinicLanguage.Value),Parameters!Payment.Value,CDbl(Parameters!Payment.Value).ToString("C"))




Kindly suggest.

Thanks & Regards,
Abhishek


Hi Abhishek,

If you don't need to change it programmatically then:

What you can do is changes the regional settings in windows itself, Then in your program it will also change.

Control panel/Region/Formats tab - additional settings/currency tab - currency symbol dropdown (change from


这篇关于如何从CultureInformation获取格式化货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆