?
Solved

How to strip off and format decimal numbers in repeater databind?

Posted on 2009-05-07
7
Medium Priority
?
1,753 Views
Last Modified: 2013-12-17
I use repeater to bind a query with a MSSQL DB table.

<asp:Label ID="balance" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "balance")%>'></asp:Label>

It displays 2344.000000000

How can I ?
1) strip off it to be 2344.00 (2 decimal places)
2) format it to be 2,344.00 (with , for each 000)

0
Comment
Question by:techques
[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
  • 3
  • 3
7 Comments
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24324134
Change the label to this:
<asp:Label ID="balance" runat="server" Text='<%# string.Format("{0:#,##0.00}", DataBinder.Eval(Container.DataItem, "balance")) %>'></asp:Label>
 
0
 

Author Comment

by:techques
ID: 24324545
Compilation Error

CS1501: No overload for method 'ToString' takes '3' arguments


<asp:Label ID="balance" runat="server" Text='<%# string.Format("{0:#,##0.00}"), DataBinder.Eval(Container.DataItem, "balance")%>'></asp:Label>

Open in new window

0
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24324589
check your code - the one you have posted is different to mine - the Text section should be:
string.Format("{0:#,##0.00}", DataBinder.Eval(Container.DataItem, "balance"))
 
you have
 
string.Format("{0:#,##0.00}"), DataBinder.Eval(Container.DataItem, "balance")
 
Check where the brackets are

Open in new window

0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:techques
ID: 24325054
sorry, you are right. I missed the ) in the end.

May I ask

I have a label

<asp:Label ID="totalbalance" runat=server></asp:Label>

in c#

if (ds.Read())
{
this.totalbalance.Text = string.Format("{0:#,##0.00}",ds["totalbalance"].ToString());
}

But, it cannot be formatted. do you know why?
0
 
LVL 12

Accepted Solution

by:
GuitarRich earned 200 total points
ID: 24325109
its probably the ds["totalbalance"].ToString() bit. If totalbalance is null that will fail - change the line to
this.totalbalance.Text = string.Format("{0:#,##0.00}",ds["totalbalance"]);
and it should be ok.
 
0
 

Author Closing Comment

by:techques
ID: 31578915
excellent !!
0
 

Expert Comment

by:edeveloper1
ID: 39194801
I have tried EVERYTHING to format a decimal number in a repeater databind and nothing works.  I still get trailing zeros no matter what I do. Any ideas?

NEVERMIND - was looking at the wrong column!!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

801 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