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

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

Title # Comments Views Activity
Convert to Hour/minute textbox and compare 3 52
How to iterate over object and get property name and value 4 26
Server Error 11 47
Entity Framework 7 31
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

22 Experts available now in Live!

Get 1:1 Help Now