[英]How to display dot using Custom Numeric Format Strings in C#
I want to display decimal
product price in format 100 грн.
我想以100 грн.
格式显示decimal
产品价格100 грн.
(Ukrainian hryvnia). (乌克兰格里夫纳汇率)。 When I use currency pattern .ToString("c")
I get ₴
sign, I don't want to use it, so I decided to try something like .ToString("#.## грн.")
but the dot isn't displayed. 当我使用货币模式.ToString("c")
我得到了₴
符号,我不想使用它,因此我决定尝试使用诸如.ToString("#.## грн.")
但点号不是' t显示。 I get грн
output but expect грн.
我得到грн
输出,但期望грн.
. 。 How can I accomplish that? 我该怎么做? I want to use string pattern as the part of the localization so I could use something like .ToString(Settings.CurrencyOutputPattern)
where CurrencyOutputPattern
is "c"
for USD
, "#.## грн."
我想使用字符串模式作为本地化的一部分,所以我可以使用.ToString(Settings.CurrencyOutputPattern)
类的东西,其中CurrencyOutputPattern
对于USD
是"c"
,是"#.## грн."
for UAH
and "#.## руб."
UAH
和"#.## руб."
for RUB
为RUB
You can include a literal .
您可以包括文字.
by enclosing it in single quotes: 通过将其用单引号引起来:
.ToString("#.## грн'.'")
you can implement your own extension of String/Decimal to make it to grivan 您可以实现自己的String / Decimal扩展名使其成为grivan
public string ToGrivna(this decimal ammount)
{
return ammount.ToString("0.##")+" грн."
}
If what you want is to change the currency, then you can clone the CurrentCulture
and modify it. 如果要更改货币,则可以克隆CurrentCulture
并进行修改。
CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
culture.NumberFormat.CurrencySymbol = "грн.";
decimal num = 10.24M;
string str = num.ToString("c", culture);
If you want to control where the currency is written (left o right), there are two properties of NumberFormat
: NumberFormatInfo.CurrencyPositivePattern and NumberFormatInfo.CurrencyNegativePattern 如果要控制货币的书写位置(从左到右),则NumberFormat
有两个属性: NumberFormatInfo.CurrencyPositivePattern和NumberFormatInfo.CurrencyNegativePattern
For example here in Italy we use € 10.00 例如,在意大利,我们使用€10.00
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.