显示前格式化数据

时间:2017-06-13 20:23:13

标签: c# asp.net-mvc razor format

目前,我显示没有格式的货币数据,女巫明显不好。在展示他之前,我想找一种格式化这些数据的方法。我使用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>

(见下图)

How data is shown currently

如何在演出前格式化?

谢谢!

1 个答案:

答案 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;

参考:Set up dot instead of comma in numeric values