Table of Contents
Returns the integer value nearest to a number.
1. Description
The round operator pops a number from the operand stack and pushes the integer value nearest to that number. If the number is equally close to two integers, round returns the greater of the two. The type of the result is the same as the type of the operand.
This is a Level 1 operator, available in all PostScript implementations.
4. Return Values
num2-
The nearest integer value to num1 (type matches num1):
-
For integers: returns the same value
-
For reals: returns real with no fractional part, rounded to nearest
-
5. Examples
5.1. Basic Rounding
% Round to nearest integer
3.2 round % → 3.0 (closer to 3)
3.7 round % → 4.0 (closer to 4)
% Tie-breaking: 0.5 rounds to greater value
3.5 round % → 4.0 (tie: chooses greater)
6.5 round % → 7.0
% Negative numbers
-4.2 round % → -4.0
-4.7 round % → -5.0
-6.5 round % → -6.0 (tie: chooses greater, less negative)
% Already integers
99 round % → 99
9. Error Conditions
stackunderflow-
The operand stack is empty.
typecheck-
The operand is not a number.
10. See Also
-
Arithmetic and Math - All arithmetic operators