Trunc
- Last UpdatedOct 04, 2024
- 1 minute read
- PI System
- PI Server 2018
- PI Server
Truncate a number or time to the next lower unit.
Syntax
Trunc(x [, unit])
Arguments
-
x
An integer or real number, time expression, or time period.
-
unit
Optional. The size of the unit to truncate to; x will be truncated to a multiple of unit. If x is a number, unit must be a number. If x is a time expression or time period, unit must be a time period. If unit is omitted, Trunc truncates to the next lower integer (for a number) or second (for a time period).
Returns
The largest multiple of unit that is less than x. For a negative x, it returns the lowest multiple of unit larger than x. The return is the same data type as x.
Exceptions
If x is a string, or if unit is of the wrong data type, an error is returned.
Notes
If x is a time, and unit is omitted, this routine has no effect, as times are only accurate to one second.
When |x| < |unit|, 0 is returned.
Example
-
Trunc(12.999)
[Returns 12, truncated to the next lower integer]
-
Trunc(28.75, 10)
[Returns 20, truncated to next lower multiple of 10]
-
Trunc('14-Dec-16 11:47', '+1h')
[Returns 12/14/2016 11:00:00 AM, truncated to next lower hour]
-
Trunc('18:47'-'15:00','+1h')
[Returns 03:00:00, truncated period to next lower hour]
Note: Truncating to the next lower day results in a timestamp of the next lower day in UTC time, not local time.