Work preparation
3.1 Flexible NC programming
%.<n>P:
460
Converting a REAL value into an INTEGER value taking into account <n> decimal
places. The INTEGER value is output as a 32-bit binary number. If the value to be
converted cannot be represented with 32 bits, then processing is interrupted with an
alarm.
As a byte sequence generated using the format statement %.<n>P can also contain
binary zeroes, then the total string that is generated in this way no longer corresponds
to the conventions of the NC data type STRING. As a consequence, it can neither be
saved in a variable, type STRING, nor be further processed using the string com‐
mands of the NC language. The only possible use is to transfer the parameter to
the WRITE command with output at an appropriate external device (see the following
example).
As soon as the <Format_String> contains a format description, type %P then the
complete string, with the exception of the binary number generated with %.<n>P, is
output corresponding to the MD10750 $MN_SPRINT_FORMAT_P_CODE in the AS‐
CII character code, ISO (DIN6024) or EIA (RS244). If a character that cannot be
converted is programmed, then processing is interrupted with an alarm.
Example:
N10 DEF REAL REAL_VAR=123.45
N20 DEF INT ERROR
N30 DEF STRING[20] EXT_DEVICE="/ext/dev/1"
...
N100 EXTOPEN(ERROR,EXT_DEVICE)
N110 IF ERROR <> 0
...
N200 WRITE(ERROR,EXT_DEVICE,SPRINT("INTEGER BINARY
CODED:%.3P",REAL_VAR)
N210 IF ERROR <> 0
... ; error handling
Result: The string "INTEGER BINARY CODED: 'H0001E23A'" is transferred to the
output device /ext/dev/1. The hexadecimal value 0x0001E23A corresponds to the
decimal value 123450.
; error handling
Programming Manual, 12/2019, 6FC5398-2EP40-0BA0
NC programming