The FORMATTED_NUM Function

As explained earlier in this document, GPP2 variables have unique format characteristics that define how they are printed in the GPP2 output. The format also affects how variables are compared to each other inside GPP2 expressions. The format does not affect the internal value of variables.

The FORMATTED_NUM function returns a numeric value that is equal to the formatted form of a given variable. Unlike most other numeric functions, it only accepts variables as arguments (and not any numeric expression).

For instance, assume variable VAR has the value 5.2299, and its format defines the maximum number of fraction digits as 2. Therefore, sending VAR to the output will print the string "5.23". FORMATTED_NUM(VAR) will return the number 5.23000

Note that use of this function does not change the internal value of the variable. In our example, VAR will remain at 5.2299.

The following statement will set VAR to its formatted value (similar to the old CONVERT statement):

VAR = FORMATTED_NUM (VAR);          Set VAR to 5.23000

The following example demonstrates the effect of FORMATTED_NUM and its importance. Assume all variables below are formatted with 3 digits after the decimal point.

Variable

Toolpath Coordinate

Internal
representation

Formatted Output (G-code)

Xold

100.0004

100.00040....

100.000

Xnew

109.9996

109.99960....

110.000

Delta1 =

Xnew - Xold

9.9992

9.99920....

9.999
(should be 10.000 !)

DELTA2 = FORMATTED_NUM(Xnew) - FORMATTED_NUM(Xold)

10.000

10.000

10.000

While the internal representation of Delta1 seems OK, the formatted output of Delta1 is not the excepted result. DELTA2 gets the correct result (both internal and output).

The FORMATTED_NUM function can also be used to convert Xold and Xnew:

  Xold = FORMATTED_NUM (Xold);       // Xold gets 100.00000
  Xnew = FORMATTED_NUM (Xnew);       
// Xnew gets 110.00000

Delta1 = Xnew - Xold;              // Delta1 gets 10.0000

FORMATTED_NUM must use a single variable argument. We cannot write:

Delta1 = FORMATTED_NUM (Xnew - Xold); // illegal expression!!!

 

Some functionality may be dependent on the product package. Contact your Reseller if you require a license.