Precision with "Format".

  • Thread starter Thread starter Robin Tucker
  • Start date Start date
R

Robin Tucker

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!)
 
Precision isn't necessarily the same as decimal places. What db is it? SQL /
Oracle / Jet?
 
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 said:
Precision isn't necessarily the same as decimal places. What db is it? SQL
/ Oracle / Jet?



Robin Tucker said:
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!)
 
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 said:
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 said:
Precision isn't necessarily the same as decimal places. What db is it?
SQL / Oracle / Jet?



Robin Tucker said:
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!)
 
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

------------------------------
message 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!)
 
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 said:
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 said:
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 said:
Precision isn't necessarily the same as decimal places. What db is it?
SQL / Oracle / Jet?



message 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!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top