By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,206 Members | 1,035 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,206 IT Pros & Developers. It's quick & easy.

Precision with "Format".

P: n/a
My database has a [Precision] column for numeric data items. How can I use
this number in the "format" command, such that for, say precision 2, I get
numbers like 2011.01 or 2387.00 and for 4 I would get 2011.0100 or
2387.0000?

(simple question I know!)
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Precision isn't necessarily the same as decimal places. What db is it? SQL /
Oracle / Jet?

"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:cu*******************@news.demon.co.uk...
My database has a [Precision] column for numeric data items. How can I
use this number in the "format" command, such that for, say precision 2, I
get numbers like 2011.01 or 2387.00 and for 4 I would get 2011.0100 or
2387.0000?

(simple question I know!)

Nov 21 '05 #2

P: n/a
I'm using SQL Server. I don't mean precision, I mean "displayed decimal
places". My "displayed decimal places" is a field, when its 2, I just want
to show aa.bb, when its 3, aa.bbb (or aaaaaaaaaa.bbb) etc. Sure this is
probably quite simple using "Format"?

"JohnFol" <Ou************@WibbleObbble.Com> wrote in message
news:ZX*****************@newsfe5-gui.ntli.net...
Precision isn't necessarily the same as decimal places. What db is it? SQL
/ Oracle / Jet?

"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:cu*******************@news.demon.co.uk...
My database has a [Precision] column for numeric data items. How can I
use this number in the "format" command, such that for, say precision 2,
I get numbers like 2011.01 or 2387.00 and for 4 I would get 2011.0100 or
2387.0000?

(simple question I know!)


Nov 21 '05 #3

P: n/a
When you say "My "displayed decimal places" is a field" what are you
displaying it in? A datagrid or a textbox? The formatting of the display
on the client has nothing to do with the database. Look at the
String.Format command if using a textbox. If you are using a datagrid there
is a format property on the DataGridTextBoxColumn object that will format
the display. The display format string you are looking for is "0.0000"

Hope it helps
Chris

"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:cu*******************@news.demon.co.uk...
I'm using SQL Server. I don't mean precision, I mean "displayed decimal
places". My "displayed decimal places" is a field, when its 2, I just
want to show aa.bb, when its 3, aa.bbb (or aaaaaaaaaa.bbb) etc. Sure this
is probably quite simple using "Format"?

"JohnFol" <Ou************@WibbleObbble.Com> wrote in message
news:ZX*****************@newsfe5-gui.ntli.net...
Precision isn't necessarily the same as decimal places. What db is it?
SQL / Oracle / Jet?

"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:cu*******************@news.demon.co.uk...
My database has a [Precision] column for numeric data items. How can I
use this number in the "format" command, such that for, say precision 2,
I get numbers like 2011.01 or 2387.00 and for 4 I would get 2011.0100 or
2387.0000?

(simple question I know!)



Nov 21 '05 #4

P: n/a
Hi,

Use a numberformatinfo. This is how to get a datagrid to display 3
digits after the decimal. Place this in your tablestyle for the grid.

Dim cm As CurrencyManager = CType(Me.BindingContext(DataGrid1.DataSource),
CurrencyManager)

Dim pd As System.ComponentModel.PropertyDescriptor =
cm.GetItemProperties()("Qty")

Dim ni As New System.Globalization.NumberFormatInfo

ni.NumberDecimalDigits = 3

Dim colQty As New DataGridTextBoxColumn(pd, "f")

With colQty

..MappingName = "Col1"

..HeaderText = "Qty"

..Width = 75

..FormatInfo = ni

End With

Ken

------------------------------
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:cu*******************@news.demon.co.uk...
My database has a [Precision] column for numeric data items. How can I use
this number in the "format" command, such that for, say precision 2, I get
numbers like 2011.01 or 2387.00 and for 4 I would get 2011.0100 or
2387.0000?

(simple question I know!)

Nov 21 '05 #5

P: n/a
Yes, I worked it out something like this:

Dim theStringToDisplay as String = "######." + "0".PadRight(myPrecision,
"0"c)

So I have a variable "displayed decimal places" according to the value of
the precision column in the database ( there is a column called [Precision]
(a tinyint) that tells me how many decimal places the user wants with his
value - we use this because I am sending up values to another piece of
custom hardware which requires this information).

Thanks.

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:%2****************@TK2MSFTNGP12.phx.gbl...
When you say "My "displayed decimal places" is a field" what are you
displaying it in? A datagrid or a textbox? The formatting of the display
on the client has nothing to do with the database. Look at the
String.Format command if using a textbox. If you are using a datagrid
there is a format property on the DataGridTextBoxColumn object that will
format the display. The display format string you are looking for is
"0.0000"

Hope it helps
Chris

"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:cu*******************@news.demon.co.uk...
I'm using SQL Server. I don't mean precision, I mean "displayed decimal
places". My "displayed decimal places" is a field, when its 2, I just
want to show aa.bb, when its 3, aa.bbb (or aaaaaaaaaa.bbb) etc. Sure
this is probably quite simple using "Format"?

"JohnFol" <Ou************@WibbleObbble.Com> wrote in message
news:ZX*****************@newsfe5-gui.ntli.net...
Precision isn't necessarily the same as decimal places. What db is it?
SQL / Oracle / Jet?

"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:cu*******************@news.demon.co.uk...
My database has a [Precision] column for numeric data items. How can I
use this number in the "format" command, such that for, say precision
2, I get numbers like 2011.01 or 2387.00 and for 4 I would get
2011.0100 or 2387.0000?

(simple question I know!)



Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.