Truncation and Rounding Functions
• floor(z)—Returns the greatest integer ≤ z.
• Floor(z, y)—Returns the greatest multiple of y ≤ z.
• ceil(z)—Returns the smallest integer ≥ z.
• Ceil(z, y)—Returns the smallest multiple of y ≥ z.
• round(z, [n])—Returns z rounded to n decimal places.
If n is omitted, returns z rounded to the nearest integer (n is assumed to be zero).
If n < 0, returns z rounded to n places to the left of the decimal point.
If the (n + 1)th decimal place is less than 5, the number is rounded down, otherwise, it is rounded up.
• Round(z, y)—Returns round(z/y) · y, which rounds z to the closest multiple of y. round(z, 1) = Round(z, 0.1).
• trunc(z)—Returns the integer part of z by removing the fractional part.
• Trunc(z, y)—Returns trunc(z/y) · y.
The uppercase versions of these functions are used to correctly evaluate the truncation of values with units. For example, if you wish to find the smallest multiple of x := 3.23m in feet, use Ceil(x, ft)=11ft.
Functions floor and trunc return the same results for positive values of z. For negative values of z, however, the results are different: floor(−2.6) = −3, but trunc(−2.6) = −2.
Arguments
• z is a real or complex scalar or vector. For the lowercase functions, z must be dimensionless. For the uppercase, two-argument, functions, z and y must have compatible units. If z is complex, the truncation or rounding is carried out separately for the real and the imaginary parts.
• y is a real, nonzero scalar or vector.
• n (optional) is an integer. The default value for n is 0.
Watch this video to learn more about truncation and rounding functions: