Solved

Format table cell in DataList to 2 decimal places

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

24 Experts available now in Live!

Get 1:1 Help Now