DataBinding Eval To 2 Decimal Place Doesn't Show 0
44,781
Solution 1
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"
Solution 2
Did you try this :
<% #Eval("Rate","{0:F2}") %>
Solution 3
This would work, it also adds a group separator: <%# Eval("Rate", "{0:n2}")%>
Author by
monkeylee
Updated on July 18, 2020Comments
-
monkeylee almost 4 years
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 0any suggests on how to bind the decimal field but still show 0
Thanks
Lee
-
RichardOD almost 15 yearsYou can work these formatting strings out more easily by using Chris Sell's .NET FormatDesigner- sellsbrothers.com/tools/#FormatDesigner
-
-
Emad Mokhtar over 11 yearsThis is a better/clean solution