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
format("%. 2f", 1.23456); This will format the floating point number 1.23456 up-to 2 decimal places, because we have used two after decimal point in formatting instruction %.
Just use %. 2f as the format specifier. This will make the Java printf format a double to two decimal places.
Eval) function is used to bind data in controls inside GridView, DataList, Repeater, DetailsView, etc. and using string. Format multiple values can be set to a single control.
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"
Did you try this :
<% #Eval("Rate","{0:F2}") %>
This would work, it also adds a group separator: <%# Eval("Rate", "{0:n2}")%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With