简体   繁体   English

如何在C#中使用自定义数字格式字符串显示点

[英]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.CurrencyPositivePatternNumberFormatInfo.CurrencyNegativePattern

For example here in Italy we use € 10.00 例如,在意大利,我们使用€10.00

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

相关问题 转换为 ASP.NET MVC / C# 中的自定义数字格式字符串 - Covert to custom numeric format strings in ASP.NET MVC / C# 数字格式字符串-使用Perstthesis(如使用C#的Excel)时,对齐正数和负数 - Numeric Format Strings - Align Positive and Negative Numbers when using Perenthesis like Excel using C# 为什么C#中的数字格式字符串在不使用小数(F0)时会对数字进行舍入? - Why do the numeric format strings in C# round the number when not using decimals (F0)? 如何使用string.Format()函数在C#中对齐字符串? - How to align strings in C# using string.Format() function? 如何使用String.Format()在C#中正确对齐字符串? - How to properly align strings in C# using String.Format()? 自定义数字格式字符串:动态小数点 - Custom Numeric Format Strings: Dynamic Decimal Point 如何对添加到组合框中的一组数字字符串进行排序? C# - How to sort a numeric set of strings that are added to a combobox? C# 如何在C#中生成格式化的Alpha数字字符串 - How to Generate formatted Alpha Numeric strings in C# 如何使用 C# 更新自定义格式 XML 文件? - How to update custom format XML file using C#? 自定义数字格式字符串,始终显示符号 - Custom numeric format string to always display the sign
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM