Fixed Decimal Fields

Decimal fields are for the entry of numbers with embedded decimal separators, such as currency values. You can use the decimal field to obtain and store fixed decimal numbers in a format that does not require floating point numbers for arithmetic operations. Decimal field numbers are stored as long integers.

The specifics for using a decimal field are summarized below:

Field Type F_DECIMAL
Header File vv_dec.h
Data Variable long data
Picture Control The allowed picture characters are 9, #, @, and U. You must put one and only one decimal character in the picture, either a hard decimal separator ('.') or a soft decimal ('@').
  The picture depends on whether user entry is to be left to right (standard) entry of data or is to be right entry.

Pictures for Standard Entry: For standard, left to right entry of data, the picture string should contain # characters and one @ character to place the soft decimal (e.g., "######@##"). The special control character @ displays initially as a decimal separator but can be deleted and overwritten. The # accepts the system decimal separator as a valid character. The suggested picture will, therefore, allow the user to enter the decimal separator where desired. If 9 were used as the control character, it would not permit entry of a decimal separator.

Pictures for Right Entry: With right entry, the cursor is locked in the right-most position of the field, and entered numbers are pushed to the left. The suggested picture to use for right entry of data is "9999999.99". The decimal separator will be printed in the field in the specified position and protected. As numbers are pushed to the left, they will skip over the protected decimal separator. The control character 9 will not allow another decimal separator to be entered. This method also prevents truncation of the user's entry. (See Chapter 9, "Data Field Processing Options," for a description of how to set the data entry option to be right entry.)

Code Example long price = 1250L;

fld_def(6, 0, "Item Price: $", FADJACENT, "#####@##",
F_DECIMAL, (PTR) &price, dfmp);

The initial field display will be:

    Item Price: $   12.50

The cursor will be at the left-most character in the field. To change the price to $14.50, the user would enter "14.50" or "14.5". The field would be cleared on the first keystroke. Alternatively, the user can place the cursor at the 2, and type a 4. When the field is exited, the entered number would be shifted flush right. The value transferred to the data variable upon form exit will be 1450.


Home Contents Previous Next