Solved

format price in repeater

Posted on 2007-11-27
6
986 Views
Last Modified: 2013-11-06
In ASP.NET 2.0 with C# I have a repeater that shows a price and I want to show it without any digit after the decimal point.
this is how I show it  inside the repeater:
<%# Eval("Price")%>
I thought of writing it like:
<%# Eval("Price","{0:N0}")%>
but it doesn't work.
How shall I write it?
Anat


0
Comment
Question by:ANAT2403
6 Comments
 
LVL 12

Expert Comment

by:needo_jee
ID: 20357481
This would not remove trailing zeros
<%# Eval("Price","{0:N0}")%>

if currency is recqired then use
<%# Eval("Price","{0:c}")%>

You may use math.ceil or math.round to remove trialing zeros
or you can parse it to int using Javascript function?
int.Parse(<%# Eval("Price","{0:c}")%>)

0
 
LVL 12

Expert Comment

by:needo_jee
ID: 20357531
sorry not int.parse
in js it should be pareint like this

parseint( <%# Eval("Price","{0:c}")%> )


'var a = parseInt(num);
'var b = parseFloat(num);
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 20357919
Try it like this

    <%# Eval("Price","{0:F0}")%>
0
 

Accepted Solution

by:
ANAT2403 earned 0 total points
ID: 20550546
Hi,
Sorry but the only thing that worked for me in to write in the code behind the following:
            Label lblMin = (Label)e.Item.FindControl("lblMinPrice");
            string minpStr = String.Format("{0:C}", decimal.Parse(lblMin.Text));
            lblMin.Text = minpStr.ToString();
Anat
0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 20572463
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

932 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

11 Experts available now in Live!

Get 1:1 Help Now