![](/img/trans.png)
[英]Displaying decimal values retrieved from Sql Server Database with thousands seperator on an Asp.net/Mvc Razor view
[英]Asp.NET MVC Razor Format Decimal? to #.###,##
我目前正在研究ASP.NET MVC 4.5应用程序。
我尝试将模型中的属性呈现为正确的数值:
ViewModel中的属性:
public decimal? Price { get; set; }
来自数据库的数据如下所示: 99999,99
我想要的格式如下: 99.999,99
在我的剃刀视图中,我使用如下属性:
@Model.Price
不幸的是,它看起来仍然像这样: 99999.99
您知道如何格式化该小数吗? 在我看来正确值吗?
是否有不使用显示模板的解决方案?
谢谢!!!
尝试这个
decimal value = 99999.99M;
string display = value.ToString("N2", CultureInfo.GetCultureInfo("es"));
展示架
99.999,99
我已经尝试了以下所有值:
"C"
用于在您的文化中显示货币
小数点后两位数字的"C2"
货币
"C2", culture
:我使用的小数点是逗号的文化
"N2", culture
:因为我只想显示数字,没有货币符号
请尝试使用本指南
using System;
using System.Globalization;
public class TestClass
{
public static void Main()
{
int i = 100;
// Creates a CultureInfo for English in Belize.
CultureInfo bz = new CultureInfo("en-BZ");
// Displays i formatted as currency for the bz.
Console.WriteLine(i.ToString("c", bz));
// Creates a CultureInfo for English in the U.S.
CultureInfo us = new CultureInfo("en-US");
// Display i formatted as currency for us.
Console.WriteLine(i.ToString("c", us));
// Creates a CultureInfo for Danish in Denmark.
CultureInfo dk = new CultureInfo("da-DK");
// Displays i formatted as currency for dk.
Console.WriteLine(i.ToString("c", dk));
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.