Round
Round(x, digits, dateUnit)
Round(x) rounds «x» to the nearest integer.
To round to a given number of «digits», i.e,. to the nearest power of 10-digits, use Round(X,digits).
Round can also be applied to dates and date-time numbers to find the nearest date at a given date increment, rounding to the nearest year, quarter, month, weekday, day, hour, minute or second. The «dateUnit» must be one of: 'Y', 'Q', 'M', 'WD', 'D', 'h', 'm', 's'. Note that 'M' and 'm' are case sensitive. Or «dateUnit» can be spelled out ('year', 'quarter', 'month', 'weekday', 'day', 'hour', 'minute', or 'second').
Library
Math
Examples
Round(1.4) → 1
Round(1.5) → 2
Round(-1.5) → 2
Round(Pi, 3) → 3.14200
Round(12345.6, -2) → 12300.0
Round(MakeDate(2010, 7, 2), dateUnit:'Y') → 2010-Jan-1
Round(MakeDate(2010, 7, 3), dateUnit:'Y') → 2011-Jan-1
Round(MakeDate(2010, 8, 2), dateUnit:'Q') → 2010-Jul-1
Round(MakeDate(2010, 8, 20), dateUnit:'Q') → 2010-Oct-1
Round(MakeDate(2010, 8, 1), dateUnit:'WD') → Monday, 2010-Aug-2
Number Format
The Round function (along with Floor and Ceil) rounds to the indicated number of digits. However, this does not determine how many digits are shown when the number is displayed. The latter is controlled by the number format settings (Ctrl+B). While Round(pi, 6) returns 3.141593, this will display as 3.142 if your number format is set to suffix with 4 digits, for example. To see the full result, you can increase the digits in the number format to the maximum (around 16).
Notes about Precision
When «digits» ≤ 6 Analytica 4.2 and higher will return an exact representation of the rounded number. To do this, internally it utilizes a fixed-point real number format. When rounding to more than 6 digits, the result may not always be an exact power of 10.
In Analytica 4.1, or in Analytica 4.2 when «digits» > 6, Round(X, digits) cannot guarantee that the result can be represented exactly as a power of 10. Analytica represents numbers using a binary floating point format. Fractions that are an exact power of 10-1 cannot always be represented exactly in binary -- i.e., they are usually not an exact power of 1/2. Therefore, non-zeros may be observed around the 16th significant digit. The number returned is a number that is as close to the rounded value as can be represented in an IEEE floating-point binary format. Rounded values generally will display as expected in result tables unless you have the number format set to show more than 15 significant digits.
Date-Time Rounding
When rounding to a date unit, the time will always be zeroed in the result (equivalent to a time of midnight). The nearest date is chosen, irrespective of the time of day, unless the two nearest dates are the same number of days away, in which case the earlier date is chosen when the fractional time portion of the date number is before noon (less than 0.5).
When rounding to "weekday" ('WD'), saturdays round to friday, and sundays round to monday. If the time portion is after noon, it will round to midnight the next day (except on Friday, which rounds to midnight on the same day).
Rounding to the nearest time unit is straightforward.
History
The «digits» parameter requires Analytica 4.1 or later. The «dateUnit» parameter requires Analytica 4.3 or later.
Enable comment auto-refresher