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
259 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
[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
  • 2
  • 2
5 Comments
 
LVL 5

Assisted Solution

by:rameedev
rameedev earned 150 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 350 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

631 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