Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I read a currency field from the database and have it display to two decimal places in a textbox?

Posted on 2006-11-22
5
Medium Priority
?
262 Views
Last Modified: 2010-04-16
Hi,

Please dont worry about any DataAccess code and the rest.
I have the following code which displays to four decimal places.

                this.txtDiscountAmount.Text = Decimal.Parse( Convert.ToString(dataReader[0]), System.Globalization.NumberStyles.Currency).ToString(); //DiscountAmount      


Any help would be appreciated.

Thanks for your time.

Cheers.
Steve
0
Comment
Question by:smacca
  • 2
  • 2
5 Comments
 
LVL 5

Assisted Solution

by:rameedev
rameedev earned 600 total points
ID: 18001273
This might help

Decimal d = Decimal.Parse("12.12.4567",System.Globalization.NumberStyles.Currency);
d = Decimal.Round(d,2);
Console.WriteLine(d.ToString())
0
 
LVL 5

Expert Comment

by:rameedev
ID: 18001274
sorry it was supposed to be 12.4567
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 18001330
You could play with ToString to format your string
try this

this.txtDiscountAmount.Text = (dataReader[0]).ToString("C",new CultureInfo( "en-US", false ).NumberFormat);
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 18001360
It's just a simple change:

  this.txtDiscountAmount.Text = Decimal.Parse(Convert.ToString(dataReader[0])).ToString("0.00"); //DiscountAmount
0
 
LVL 11

Accepted Solution

by:
Expert1701 earned 1400 total points
ID: 18001365
Or, if you want seperators on the thousands, use:

  this.txtDiscountAmount.Text = Decimal.Parse(Convert.ToString(dataReader[0])).ToString("#,##0.00"); //DiscountAmount
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

927 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