Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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
?
260 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 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