Programming Q parameters | Programming examples
9.13 Programming examples
Example: Rounding a value
The INT function truncates the decimal places.
In order for the control to round correctly, rather than simply
truncating the decimal places, add the value 0.5 to a positive
number. For a negative number you must subtract 0.5.
The control uses the SGN function to detect whether a number is
positive or negative.
0 BEGIN PGM ROUND MM
1 FN 0: Q1 = +34.789
2 FN 0: Q2 = +34.345
3 FN 0: Q3 = -34.432
4 ;
5 Q11 = INT (Q1 + 0.5 * SGN Q1)
6 Q12 = INT (Q2 + 0.5 * SGN Q2)
7 Q13 = INT (Q3 + 0.5 * SGN Q3)
8 END PGM ROUND MM
HEIDENHAIN | TNC 620 | Klartext Programming User's Manual | 01/2022
First number to be rounded
Second number to be rounded
Third number to be rounded
Add the value 0.5 to Q1, then truncate the decimal places
Add the value 0.5 to Q2, then truncate the decimal places
Subtract the value 0.5 from Q3, then truncate the decimal
places
9
351