Solved

Format table cell in DataList to 2 decimal places

Posted on 2013-06-11
2
657 Views
Last Modified: 2013-06-12
In a DataList, I have a table cells like so:
<%#Convert.ToString(DataBinder.Eval(Container.DataItem, "TotalAmount"))%>
<%#Convert.ToDecimal(DataBinder.Eval(Container.DataItem, "DepositAmount"))%>

Open in new window

It displays numbers to 4 decimal places, like 123.4500. I want only 2 decimal places - 123.45.
How do I get this?
0
Comment
Question by:allelopath
2 Comments
 
LVL 15

Assisted Solution

by:pateljitu
pateljitu earned 250 total points
ID: 39241284
Please try code as suggested:

<%# String.Format("{0:f2}", Convert.ToDecimal(DataBinder.Eval(Container.DataItem, "TotalAmount")))%>
<%# String.Format("{0:f2}", Convert.ToDecimal(DataBinder.Eval(Container.DataItem, "DepositAmount")))%>

Open in new window

0
 
LVL 28

Accepted Solution

by:
sammySeltzer earned 250 total points
ID: 39241909
You can do this on the markup too:

               <asp:Label ID="TotalAmount" runat="server" Text='<%# Eval("TotalAmount","{0:c2}" ) %>' />
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question