Link to home
Start Free TrialLog in
Avatar of DeniseGoodheart
DeniseGoodheart

asked on

How to Format DataGridView Cell

Good Day:

I am creating a WinForms application using VS.NET 2005, VB.NET, and the DataGridView control.  The Unit Price cell on my DataGridView control rounds my number and I do not want the numbers to be rounded.  For example, .375 gets rounded to .38.  How do I format so it does not round the number?  My format code is as follows:

grdDetail.Columns("Unit Price").DefaultCellStyle.Format = "#,###,###.00"

Any Suggestions?
Thank You,
Denise
ASKER CERTIFIED SOLUTION
Avatar of theplonk
theplonk
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DeniseGoodheart
DeniseGoodheart

ASKER

Hello,

Thank you for posting your code. I was hoping for a simple format code.  There has to be an easier way.
Hello,

I figured it out.  I simply added an extra 0 at the end as follows:
Me.grdDetail.Columns("Unit Price").DefaultCellStyle.Format = "#,###,###.000"

Cheers,
Denise
That's no prob. Apologies, i assumed you wanted the value to two decimal places without rounding up.
For any reference to existing standard or custom numeric format specifiers. Just check out:
http://msdn.microsoft.com/en-us/library/427bttx3.aspx