Solved

Format table cell in DataList to 2 decimal places

Posted on 2013-06-11
2
658 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 29

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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