Sunday, April 3, 2011

DataBinding Eval To 2 Decimal Place Doesn't Show 0

Hi,

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 than 4.5 if I use <% #Eval("Rate","{0:#.##}") %> it shows 4.5 but doesn't display 0

any suggests on how to bind the decimal field but still show 0

Thanks

Lee

From stackoverflow
  • 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"
    
    monkeylee : excellent worked well String.Format("{0:0.##}", 123.0);
  • Did you try this :

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

0 comments:

Post a Comment