c# - 显示的货币格式

标签 c# .net asp.net globalization currency

有没有办法为一个国家/地区设置正确的货币表示格式?

例子 英国 - £127.54 荷兰 € 127,54- 美国 $127.54

等..

一些需要考虑的事情,

  1. 货币符号

  2. 货币符号放置 -- 可以 位于之前或之后 数字。

  3. 负数显示

最佳答案

试试 Currency Format Specifier (“C”)。它会自动考虑当前的 UI 文化并相应地显示货币值。

您可以将它与 String.Format 一起使用或为数字类型重载的 ToString 方法。

例如:

decimal value = 12345.6789M; // Be sure to use Decimal for money values. Do not use IEEE-754 types such as float (System.Single) and double (System.Double) as they can only store approximate values.
Console.WriteLine(value.ToString("C", CultureInfo.CurrentCulture));

Console.WriteLine(value.ToString("C3", CultureInfo.CurrentCulture));

Console.WriteLine(value.ToString("C3", CultureInfo.CreateSpecificCulture("da-DK")));

// The example displays the following output on a system whose
// current culture is English (United States):
//       $12,345.68
//       $12,345.679
//       kr 12.345,679

关于c# - 显示的货币格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4842332/

相关文章:

jQuery 对话框回发但 UpdatePanel 未更新

c# - 如何安装网页 v1.0

asp.net - "User Preferences"数据库表设计

asp.net - mvc 大写模型与小写模型

c# - 在许多类中实现新接口(interface)成员的最快方法?

c# - 我怎么知道我的代码中的什么触发了这个“System.ObjectDisposedException”?

c# - 将相同的标签分组并一起更改文本 - c#/Javascript

c# - 为什么我的程序没有使用正确版本的 ITextSharp?

c# - 以下语法中方括号 "[]"的用途是什么

c# - 如何使用 ExecuteSqlInterpolatedAsync() 在 EF Core 3.0 中使用输出参数