Solved

Format table cell in DataList to 2 decimal places

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

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 article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

635 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