views:

1294

answers:

2

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

+1  A: 

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"
Blixt
excellent worked well String.Format("{0:0.##}", 123.0);
monkeylee
A: 

Did you try this :

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