和使用的CultureInfo Decimal.ToString的(; C"")自定义货币符号和小数 [英] Custom Currency symbol and decimal places using decimal.ToString("C") and CultureInfo
问题描述
我有 Decimal.ToString的(C)
覆盖问题。我想要做的基本上就是
如下:
CultureInfo的usCulture =新的CultureInfo(EN-US) ;
Thread.CurrentThread.CurrentCulture = usCulture;
的NumberFormatInfo LocalFormat =(的NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
LocalFormat.CurrencySymbol =RM;
我想使上述代码的函数(覆盖的ToString(C)),由此当下列代码得到执行:
小数支付= Convert.ToDecimal(DR [TotalPaids]);
lblPaids.Text = paid.ToString(C);
结果将RM4,900.00而不是$ 4,900.00
我如何创建一个 Decimal.ToString的(C)
这将解决我的问题。
<一个覆盖p>在此先感谢。
要得到一个编码格式RM 11,123,456.00你还需要设置以下属性。
修改的CurrentCulture =新的CultureInfo(Thread.CurrentThread.CurrentCulture.Name);
Thread.CurrentThread.CurrentCulture =修改;
VAR NUMBERFORMAT = modified.NumberFormat;
numberFormat.CurrencySymbol =RM;
numberFormat.CurrencyDecimalDigits = 2;
numberFormat.CurrencyDecimalSeparator =;
numberFormat.CurrencyGroupSeparator =,;
如果你这样做,在应用程序启动然后,应该让MS-MY格式样的en-US但在RM货币符号每次调用的ToString(C)
方法。
I have a problem with decimal.ToString("C")
override.
Basically what I wants to do is as follows:
CultureInfo usCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = usCulture;
NumberFormatInfo LocalFormat = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
LocalFormat.CurrencySymbol = "RM";
I wants to make above code a function (override ToString("C")) whereby when the following code get executed:
decimal paid = Convert.ToDecimal(dr["TotalPaids"]);
lblPaids.Text = paid.ToString("C");
The results would be RM4,900.00 instead of $4,900.00
How do I create an override for decimal.ToString("C")
that would solve my problem
Thanks in advance.
To get a format like RM 11,123,456.00 you also need to set the following properties
CurrentCulture modified = new CultureInfo(Thread.CurrentThread.CurrentCulture.Name);
Thread.CurrentThread.CurrentCulture = modified;
var numberFormat = modified.NumberFormat;
numberFormat.CurrencySymbol = "RM";
numberFormat.CurrencyDecimalDigits = 2;
numberFormat.CurrencyDecimalSeparator = ".";
numberFormat.CurrencyGroupSeparator = ",";
If you do that at application startup then that should make ms-MY format like en-US but with the RM currency symbol every time you call the ToString("C")
method.
这篇关于和使用的CultureInfo Decimal.ToString的(; C"")自定义货币符号和小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!