Floating Point Fields

If you want to use floating point fields, you may have to set the compile and link commands so that you can access the floating point library routines supplied with your compiler. Some compilers require that you add a parameter or set a switch in the compile command statement. You may also need to add a reference to the compiler's floating point library, if it is separate, in your link statement. Consult your compiler manual.

Important: When you enable entry of floating point numbers, the size of your executable files will increase by several kilobytes, depending upon your compiler, because you will now need to link in your compiler's floating point library routines. Our floating point routines also make use of , which will add several thousand more bytes to code size. This latter increase will not occur if you were already using these or other members of the family (including our function ) elsewhere.

The specifics for using a floating point field are summarized below:

Field Type F_SINGLE, F_DOUBLE
Header File vv_singl.h, vv_doubl.h
Data Variable float data, double data
Picture Control The allowed picture control characters for floating point fields are #, 9, @ and U. The number of decimal places specified in the picture determine the number of decimal places that will be stored in the data variable.
  Pictures for Decimal Notation: The suggested picture format is "#####@##" for normal entry fields (left to right typing). This will allow the user to clear the initial value and re-enter the decimal separator. However, note that because two decimal places are specified in the picture, only two decimal places will be stored in the data variable upon form exit, regardless of the number of decimal places that might be entered by the user.

You can ensure that the number of entered decimal places equals the number specified in the field by using a hard decimal separator character. The picture would then be "99999.99". With this picture, you would generally want to set the field for right entry, because the decimal separator is fixed and cannot be moved or overwritten.

  Pictures for Scientific Notation: You can define a picture string without an explicit "E", since the picture control character # allows the entry of either an "e" or "E". A lowercase "e" will be converted to uppercase.

Otherwise, you must include an uppercase "E" in the picture and include enough spaces to the right of the "E" for a sign and the maximum number of digits that could appear in the exponent. This number depends on your compiler.

A typical picture for scientific notation would be "######@###E####". Because the field contains a protected character (the "E") it cannot be right-adjusted upon exit. This picture will allow full editing of the field and allows shifting of characters from the mantissa into the exponent.





To prevent the user from using the insert mode in the field, you can use the picture: "######@###E9999". The entry of numbers will be controlled as before, except that insertion of characters in a full mantissa or full exponent will not be allowed.

The recommended picture for preventing truncation of the user's entry is a full precision picture, such as "99.999999E9999" for a double-precision float field.

Code Example double size;
float price;
size = 1234567.8;
price = 12.50;

fld_def(6, 0, "Size: ", FADJACENT, "99.999999E9999",
F_DOUBLE, (PTR) &size, dfmp);
fld_def(7, 0, "Item Price: $", FADJACENT, "#####@##",
F_SINGLE, (PTR) &price, dfmp);
  The entry in the size field would be initially displayed as:

12.345670E+005

  The entry in the price field would be initially displayed as:

12.50


Home Contents Previous Next