2017-06-13 34 views
0

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

我该怎么让之前格式化这个?

谢谢!

+0

到底在找什么格式的,什么是所需的输出? –

+0

我想将“R $ 1542354.51”等货币字段设置为“R $ 1.542.354,51”。 – Csorgo

回答

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

+0

这很有用!非常感谢,但..和货币领域? – Csorgo

+0

使用来自stackoverflow上另一个线程的答案编辑。 –