DataBinding Eval To 2 Decimal Place Doesn't Show 0

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

Answers


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}")%>


In addition to using <% #Eval("Rate","{0:F2}") %> I also use: style="text-align:right" Instead of trying to make the format do the correct number of digits. Of course this could also be a CSS setting in the css file, instead of inline CSS.


At server side Convert Decimal 2 place into 1 place. (Decimal Value).ToString("0.0");


Need Your Help

Java NIO FileChannel versus FileOutputstream performance / usefulness

java optimization file nio operations

I am trying to figure out if there is any difference in performance (or advantages) when we use nio FileChannel versus normal FileInputStream/FileOuputStream to read and write files to filesystem. I

How to show 2 line in one column in datatable?

jsf jsf-2 primefaces datatable alignment

I have a data table in my application. One column have heavy data which increasing the width of table.