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

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
smaccaAsked:
Who is Participating?
 
Expert1701Connect With a Mentor Commented:
Or, if you want seperators on the thousands, use:

  this.txtDiscountAmount.Text = Decimal.Parse(Convert.ToString(dataReader[0])).ToString("#,##0.00"); //DiscountAmount
0
 
rameedevConnect With a Mentor Commented:
This might help

Decimal d = Decimal.Parse("12.12.4567",System.Globalization.NumberStyles.Currency);
d = Decimal.Round(d,2);
Console.WriteLine(d.ToString())
0
 
rameedevCommented:
sorry it was supposed to be 12.4567
0
 
Mohammed NasmanSoftware DeveloperCommented:
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
 
Expert1701Commented:
It's just a simple change:

  this.txtDiscountAmount.Text = Decimal.Parse(Convert.ToString(dataReader[0])).ToString("0.00"); //DiscountAmount
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.