Solved

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

Posted on 2009-05-07
7
1,751 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
Independent Software Vendors: 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!

 

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 50 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

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

Title # Comments Views Activity
Record locking on classic ASP 3 62
asp.net, radiobuttonlist, c# 3 67
Validation for a field in asp.net 3 29
What are MicroServices? 4 67
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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

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