Round
- Last UpdatedMar 04, 2025
- 2 minute read
- PI System
- PI Server 2018
- PI Server
Round a number or time to the nearest unit.
Syntax
Round(x [, unit] [, roundingMode])
Arguments
-
x
Integer, real number, time expression, or time interval
-
unit
Optional. The size of the unit to round to. If x is a number, unit must be a number. If x is a time expression or time period, unit must be a time expression. If unit is omitted, the Round function rounds to the nearest even integer (for numbers) or second (for time expressions).
-
roundingMode
Optional. The type of rounding to apply. Using the string "AwayFromZero" applies rounding of midpoint values away from zero. Omission of this parameter, or the use of "ToEven", applies the default banker's rounding.
Returns
The nearest value to x which is an integer multiple of unit. Returns the same data type as x. For more details, see the following examples.
Exceptions
If x is a string, or if unit is of the wrong data type, an error value is returned.
Notes
The system uses a banker's rounding which rounds a number to the nearest even number.
If x is time and unit is omitted, this routine has no effect: times are accurate only to a second.
Unit of measure of the argument, if it exists, is carried over to the result.
Example
-
Round(12.499)
[Returns 12 (rounded to the nearest integer)]
-
Round(12.5)
[Returns 12 (rounded to the nearest even integer)]
-
Round(12.5, "AwayFromZero")
[Returns 13 (rounded up to the nearest integer)]
-
Round (13.5)
[Returns 14 (rounded to the nearest integer)]
-
Round(13.45, 0.1)
[Returns 13.4 (rounded to the nearest even number in one decimal place)]
-
Round(13.45, 0.1, "AwayFromZero")
[Returns 13.5 (rounded up to the nearest number in one decimal place)]
-
Round(1285, 10)
[Returns 1280 (rounded to the nearest even 10)]
-
Round(1285, 10, "AwayFromZero")
[Returns 1290]
-
Round(1285, 10, "ToEven")
[Returns 1280 (rounded to the nearest even 10)]
-
Round('14-Dec-16 11:47:16')
[Returns 14-Dec-16 11:47:16 (rounded to the nearest second)]
-
Round('14-Dec-16 12:30', '+1h')
[Returns 14-Dec-97 12:00:00 (rounded to the nearest even hour)]
-
Round('18:47:15'-'15:00:09')
[Returns 03:47:06 (rounded to the nearest second)]
-
Round('18:45:40'-'15:15:10','+1m')
[Returns 03:30:00 (rounded to the nearest minute)]
Note: Rounding to the nearest day results in a timestamp of the closest day in Universal Time Coordinated (UTC) time, not local time. Use the Floor function if you want to round down to the nearest integer. Use the Ceiling function to round up to the nearest integer.