You are here: Development Standards > OSAS Standards > Coding Conventions > Numeric Display and Overflow Checking

# Numeric Display and Overflow Checking

Beginning in version 5.00, users can specify the number of decimal places in various types of numeric variables throughout the system. Follow the guidelines below for numeric mask assignment, proper numeric display with numeric overflow (error 43) checking, and precision handling.

Assigning Numeric Masks

Assign your numeric masks at the top of each program chain between lines 300 and 898. The common convention is to use variable names beginning with M. In older programs, masks are assigned to variables M0$, M1$, and so on. In newer programs, the names are more meaningful, such as MDOLL$, MQTY$, and so on.

The setup program assigns to global strings the numeric masks and numeric precision for each type of numeric, based on the user-defined numerics set up in the Company Information function. Here are the global strings used:

Numeric Types | Mask Variable | Precision Variable
Currency/Dollars | +DOLL | -DOLL
Quantities | +IQTY | -IQTY
Unit Cost | +INUC | -INUC
Unit Price | +INUP | -INUP
Credit Limits | +CRED | -CRED
Hourly Rates | +RATE | -RATE
Hours | +HOUR | -HOUR
GL Dollars | +GDOL | -GDOL
GL Dollars w/ Commas | +GCOM | -GCOM

Follow this convention for assigning numeric masks:

`0300 LET MDOLL$=“-”+STBL(“+DOLL”); REM “Mask w/ leading minus for screen display`
`0300 LET MDOLL$=STBL(“+DOLL”)+”-”; REM “Mask w/ trailing minus for reports`

Printing Numbers on Screens and Reports

Once you have established the variables containing the numeric masks, you can use the mask to print a number on the screen or in a report using the FNNUM$() or FNGUINUM$() function, which is defined with the GENNUM mergeable routine. For example, to display the variable A5 using the MDOLL$ mask, use this line:

`7540 PRINT @(15,4),FNNUM$(A5,MDOLL$)`

The FNNUM$() function returns a string containing the result of masking the numeric variable (A5) into the specified mask (MDOLL$). If the numeric value exceeds the integer mask size, the string will return asterisks (‘*’). This prevents mask overflow errors in screen display and report printing.

For GUI screens, the line of code would read

`7540 PRINT (OSGUI.CHAN)’TITLE’(4010,FNGUINUM$(A5,MDOLL$,4010))`

You must pass the control ID into the function. The function then resets the mask for the control.

Precision Handling

Maintain the precision of numeric variables, using either the precision method or the rounding method. In either case it is good practice to determine each precision value and the maximum precision at the beginning of the program.

For example, if your program uses variables with currency, unit cost and unit price precision, set DOPR, UCPR and UPPR to their respective precision values, and MXPR to the maximum of those three values, as follows:

`0100 LET DOPR=NUM(STBL(“-DOLL”))`
`0102 LET UCPR=NUM(STBL(“-INUC”))`
`0104 LET UPPR=NUM(STBL(“-INUP”))`
`0106 LET MXPR=MAX(DOPR,UCPR,UPPR)`

The rest of your program should use one of the methods outlined below

Note: The rounding method is the preferred method of handling precision, in that it is always obvious which precision is being used in any calculation.

Precision Method

Set the appropriate PRECISION before mathematical calculations containing multiplication or division, or before functions that perform these calculations internally:

`1000 PRECISION DOPR`
`1010 LET A5=A4/X`
`1020 LET A6=MOD(A4,2)`

Set the maximum PRECISION before I/O operations:

`3000 PRECISION MXPR`
`3010 WRITE (FILE[3],ERR=GENERROR)IOL=ARINXXX`

Rounding Method

Set maximum PRECISION at the beginning of each program:

`0110 PRECISION MXPR`

Perform a ROUND() function on any mathematical calculations containing multiplication or division, or on functions that perform these calculations internally:

`1020 LET A5=ROUND(A4/X,DOPR)`
`1030 LET A6=ROUND(MOD(A4,2),DOPR)`

There is no need to set PRECISION before file writes, because you set the PRECISION to the maximum at the beginning of the program.