在 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>
}

我想自己表达货币格式

喜欢 285.00 美元

我试过 CurrencyPositivePattern,但都失败了。

index.cshtml 文件中,我该怎么做?

谢谢。

尝试这样的事情:

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

这会先输出USD $,然后取Price的值,格式化成小数点后2位,数值化。

请参阅 this official MS docs 了解有关如何正确设置数值格式以及您必须这样做的所有选项的更多详细信息。