DataBinding Eval To 2 Decimal Place Doesn't Show 0

后端 未结 5 2087
旧时难觅i
旧时难觅i 2021-02-05 12:52

Platform: C# ASP.NET 3.5

I have a ListView which builds a Rate field which is decimal, if I simply have <% #Eval(\"Rate\") %> it shows 4.5000 rather t

5条回答
  •  抹茶落季
    2021-02-05 13:19

    Using #.## in the format means it should hide 0. Use 0.00 instead:

    <%# Eval("Rate", "{0:0.00}") %>
    

    See these examples:

    String.Format("{0:0.00}", 123.4567);   // "123.46"
    String.Format("{0:0.00}", 123.4);      // "123.40"
    String.Format("{0:0.00}", 123.0);      // "123.00"
    String.Format("{0:0.##}", 123.4567);   // "123.46"
    String.Format("{0:0.##}", 123.4);      // "123.4"
    String.Format("{0:0.##}", 123.0);      // "123"
    

提交回复
热议问题