Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

Make it so there always two digits after the decimal point for displaying a "total" column

I have an access database I'm accessing using oledb in C#. I have two fields (quantity and unit price) that I am multiplying to display in a datagrid as "total." The problem is that when the total ends up being a number like $3.20, it gets displayed as 3.2

So, how can I make sure that there are always 2 digits after the decimal point? Does the answer lie in the sql itself, or is there c# code that will do this?
0
patrickmulcahy
Asked:
patrickmulcahy
  • 3
  • 3
1 Solution
 
testnCommented:
web or windows form?
0
 
patrickmulcahyAuthor Commented:
web form
0
 
testnCommented:
when you put dataformat in there, make sure that you put the format string to be {0:N2} or {0:#,##0.00}
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
testnCommented:
like this...
http://aspnet.4guysfromrolla.com/articles/041702-1.2.aspx
<asp:BoundColumn DataField="yourfield" DataFormatString="{0:#,###}" ...... />
0
 
patrickmulcahyAuthor Commented:
What do you mean, In the actual database? How about using sql?
0
 
patrickmulcahyAuthor Commented:
Okay, just saw the link. I'll try this on Monday. Thanks. Time to go home.
0
 
dunglaCommented:
You can make change to your sql, in UnitPrice and Quantity, change sclae up to 2. For example

Quantity - decimal - length = 9,
Look at below for Column tab:

Precision: 18
Scale: 2 (allow 2 digit after point)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now