简体   繁体   English

如何将字符串格式化为越南语货币?

[英]How to format a string as Vietnamese currency?

If I set Format in [Region and Language] to US... 如果我将[区域和语言]中的格式设置为US ...

CultureInfo cul = CultureInfo.CurrentCulture;
string decimalSep = cul.NumberFormat.CurrencyDecimalSeparator;//decimalSep ='.'
string groupSep = cul.NumberFormat.CurrencyGroupSeparator;//groupSep=','
sFormat = string.Format("#{0}###", groupSep);
string a = double.Parse(12345).ToString(sFormat);

The result is: 12,345 (is correct) 结果是: 12,345 (是正确的)

But if I set the format in [Region and Language] to VietNam, then the result is: 12345 但是如果我将[Region and Language]中的格式设置为VietNam,那么结果是: 12345

The result should be 12.345 . 结果应该是12.345

Can you help me? 你能帮助我吗? Thanks. 谢谢。

You are helping too much. 你太过分了。 The format specifier is culture insensitive, you always use a comma to indicate where the grouping character goes. 格式说明符对文化不敏感,您始终使用逗号来指示分组字符的位置。 Which is then substituted by the actual grouping character when the string is formatted. 然后在格式化字符串时由实际的分组字符替换。

This formats correctly: 格式正确:

        CultureInfo cul = CultureInfo.GetCultureInfo("vi-VN");   // try with "en-US"
        string a = double.Parse("12345").ToString("#,###", cul.NumberFormat);

You should actually use "#,#" to ensure it still works in cultures that have a uncommon grouping. 您应该使用“#,#”来确保它仍然适用于具有不常见分组的文化。 It wasn't clear from the question whether that mattered or not so I punted for "#,###" 关于这个问题是否重要尚不清楚,所以我为“#,###”而喋喋不休

Try something like this: 尝试这样的事情:

var value = 8012.34m;
var info = System.Globalization.CultureInfo.GetCultureInfo("vi-VN");
Console.WriteLine(String.Format(info, "{0:c}", value));

The result is: 结果是:

8.012,34 ₫

Oh, and with the value 12345 the result is 12.345,00 ₫ . 哦,值12345 ,结果是12.345,00 ₫

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

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