简体   繁体   English

在 ASP.NET 5 C# 中格式化货币

[英]Format currency in ASP.NET 5 C#

 @model IQueryable<Product> @foreach (var p in Model ) { <div> <h3>@p.Name</h3> @p.Description <h4>@p.Price.ToString("C", new CultureInfo("us-US"))</h4> </div> }

I would like to express the currency format on my own.我想自己表达货币格式。

Like USD $ 285.00喜欢 285.00 美元

I tried with CurrencyPositivePattern , but failed all.我尝试过CurrencyPositivePattern ,但都失败了。

In index.cshtml file, how can I do this?index.cshtml文件中,我该怎么做?

thank you.谢谢。

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

<h4>USD $ @p.Price.ToString("n2")</h4>

This will output USD $ first, and then take the Price value and format it to 2 digits after the decimal point, numerically.这将首先输出USD $ ,然后获取Price值并将其格式化为小数点后 2 位数字。

See this official MS docs for more details on how to properly format numeric values, and all the options you have to do so.有关如何正确格式化数值的更多详细信息,以及您必须这样做的所有选项,请参阅此官方 MS 文档

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

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