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: 18358
  • Last Modified:

How to format decimal figures limiting the # of decimals, place commas or not. Same for currency.

I am loading a datagrid with a decimal field and have chosen a "C" format in my column mapping.  The source field is decimal, scale of 0.  The display gives me $ sign, commas and two decimals.  I went to a format "D" and the same result minus the $ sign.  I think there should be a rather easy way to control the basic numeric display formatting but beyond using "C" or "D" I can't seem to find the answer.  Also, will the answer work for a text box as well?
0
JayNichols
Asked:
JayNichols
  • 3
  • 2
1 Solution
 
LacutahCommented:
# = Optional Number
0 (zero) = Required Number

To format a decimal with up to 5 but always at least 3 decimal places:
#.000##

with that format 3.141596 will be displayed as "3.14159" and 0.6 would be displayed as ".600"
0
 
LacutahCommented:
I'm going to double-check that answer - I've been using Access 97 formatting too much lately..
0
 
JayNicholsAuthor Commented:
I'm going to have to have a VB.NET answer.  Thanks anyway.  I think it is in the column formatting but can't seem to find anything that will do the job.  Possibly just blind. :-)  

However the results of your answer is exactly what I am looking for.  Say, for the 3.141596, being able to view it as 3 or 3.14, etc.  Same for currency.  
0
Industry Leaders: 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!

 
amyhxuCommented:
if you use customed dataGrid Column Style, when adding the decimal column, simply add: TextBoxCol.Format = "##,##0.00"

Otherwise,
Dim dgtb As DataGridTextBoxColumn = dataGrid1.TableStyles(0).GridColumnStyles("YourDecimalColumnName")
dgtb.Format = "##,##0.00"
0
 
LacutahCommented:
For Currency, use:
$#,##0.00

The formatting is same (still), this is legacy stuff...  I was refering to using Access' formatting lots, and rarely having to use it in .NET, but the format codes (in this case) are the same which is where I was concerned.
0
 
JayNicholsAuthor Commented:
Thank you, one and all.  Lacutah, I gave you the points but amyhxu was exceedingly helpful as well.  Is there anyway in this system one can split the points?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

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