DF_FIELD_PRECISION
See Also: Get_Attribute, Set_Attribute
The number of decimal places in a numeric field.
Level
Column
Supported by
All Drivers
Type
Integer, permanent
Access
Read / Write
Values
0 ~ maximum number of decimal positions for the back end in use
Remarks
Field precision is the number of digits to the right of the decimal separator. The total number (including decimal digits) of digits in a column can be found via the DF_FIELD_LENGTH attribute.
If you wish to create a numeric field with digits after the decimal point, you must set the DF_FIELD_PRECISION attribute for that field after setting the DF_FIELD_LENGTH attribute. If you wish to create a numeric field without digits after the decimal point, it is not necessary to set the DF_FIELD_PRECISION attribute for that field.
This is a permanent attribute that can only be set inside a Structure_Start ... Structure_End operation.
In the Embedded Database, numeric columns are stored as binary coded decimal values where each nibble uses four bits. Since the length of a column always spans complete bytes, the length of a numeric column is always an even value. When DF_FIELD_PRECISION is set, the value provided will be rounded up to an even number with a maximum size of 8.
If the field addressed is not numeric, you will receive an error (Bad attribute value).
Example Procedures
ShowPrecision
Procedure ShowPrecision Handle hTable
String sTable sColumn
Integer iNumColumns iColumn iType iPrecision iLength
Get_Attribute DF_FILE_ROOT_NAME Of hTable To sTable
Showln "The columns in table " sTable " have the following names:"
Get_Attribute DF_FILE_NUMBER_FIELDS Of hTable To iNumColumns
For iColumn From 1 To iNumColumns
Get_Attribute DF_FIELD_NAME Of hTable iColumn To sColumn
Show (Right(" " + String(iColumn), 5)) ": " sColumn
Get_Attribute DF_FIELD_TYPE Of hTable iColumn To iType
Get_Attribute DF_FIELD_LENGTH Of hTable iColumn To iLength
If (iType <> DF_BCD) ;
Showln "(" iLength ")"
Else Begin
Get_Attribute DF_FIELD_PRECISION Of hTable iColumn To iPrecision
If (iPrecision > 0) ;
Showln "(" (iLength - iPrecision) "," iPrecision ")"
Else ;
Showln "(" iLength ")"
End
Loop
End_Procedure
This example loops through all the columns in the table and displays the field name and the size of the column.
AddAmountColumn
Procedure AddAmountColumn Handle hTable
Integer iColumn
Open hTable Mode DF_EXCLUSIVE
Structure_Start hTable
Move 0 To iColumn
Create_Field hTable At iColumn
Set_Attribute DF_FIELD_NAME Of hTable iColumn To "Amount"
Set_Attribute DF_FIELD_TYPE Of hTable iColumn To DF_BCD
Set_Attribute DF_FIELD_LENGTH Of hTable iColumn To 8
Set_Attribute DF_FIELD_PRECISION Of hTable iColumn To 2
Structure_End hTable
End_Procedure
This example adds a field named Amount, of type BCD (Numeric) and length 8, with 6 digits before and 2 digits following the decimal point to the end (as the last field) of the table.