目前,我显示没有格式的货币数据,女巫明显不好。在展示他之前,我想找一种格式化这些数据的方法。我使用asp.net mvc和Razor。
<table class="table table-striped" >
<tr>
<th style="min-width:130px;">Month</th>
<th style="min-width:80px;">Value 1</th>
<th style="min-width:100px;">Value 2</th>
<th style="min-width:100px;">Value 3</th>
</tr>
@foreach (TB_DADOS dados in dm){
<tr>
<td>@dados.DT_MONTH.ToString(CultureInfo.CreateSpecificCulture("pt-BR"))</td>
<td><span class="money" /> @dados.Value1</td>
<td><span class="money" /> @dados.Value2</td>
<td><span class="money" /> @dados.Value3</td>
</tr>
}
</table>
(见下图)
如何在演出前格式化?
谢谢!
答案 0 :(得分:0)
使用DateTime.ToShortDateString():https://msdn.microsoft.com/pt-br/library/system.datetime.toshortdatestring(v=vs.110).aspx
对于货币,试试这个:
System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
customCulture.NumberFormat.NumberDecimalSeparator = ",";
System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;