Solved

Format table cell in DataList to 2 decimal places

Posted on 2013-06-11
2
656 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

947 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now