Roundfrac
- Last UpdatedJan 11, 2023
- 1 minute read
- PI System
- PI Server 2024 R2
- PI Server
Round a numeric value x to y decimal places.
Syntax
Roundfrac(x, y [,roundingMode] )
Arguments
-
x
Must be an integer, real number or time expression
-
y
Integer that specifies the number of decimal places to round x to
-
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 value of x rounded to y decimal places. Returns the same data type as x. For more details, see the examples
Exceptions
If x is a string, neither a numeric value nor a time expression, returns an error
Notes
The system uses a banker's rounding which rounds a number to the nearest even number.
Unit of measure of the argument, if it exists, is carried over to the result.
If x is time and unit is omitted, this routine has no effect: times are accurate only to 1 second.
Example
-
Roundfrac (Pi(), 4)
[Returns 3.1416 ]
-
Roundfrac (0.005, 2)
[Returns 0]
-
Roundfrac (0.005, 2, "ToEven")
[Returns 0]
-
Roundfrac (0.005, 2, "AwayFromZero")
[Returns 0.01]
-
Roundfrac (TagVal('att1'), 2)
[Return the value of 'att1' rounded to 2 decimal places]