round(X;Y)
Returns the result of rounding the first given value to the nearest multiple of the second given value.
Syntax
round(X;Y)
Input
Argument | Type | Description |
---|---|---|
X |
any numeric type | The number to round to the nearest multiple of Y |
Y |
any numeric type | The nearest multiple to round X |
Return Value
Returns a numeric value corresponding to X
rounded to the nearest multiple
of Y
.
If both X
and Y
are integers, the result is an integer;
otherwise, the result is a decimal number.
If X
and/or Y
is N/A, the result is N/A.
round(X;Y)
can also round time into intervals. If
X
and Y
are in the format
'HH:MM:SS'
, the result is the time rounded
up to the next time interval specified in Y
.
Y
must be written as a string (single
quotes).
Sample Usage
X |
Y |
round(X;Y) |
---|---|---|
149.456 | 0.01 | 149.46 (decimal) |
149.456 | 1 | 149 (decimal) |
149.456 | 0.05 | 149.45 (decimal) |
149.456 | 5 | 150 (decimal) |
7 | 5 | 5 (integer) |
8 | 5 | 10 (integer) |
8.0 | 5 | 10 (decimal) |
NA | 1 | NA (integer) |
1.0 | NA | NA (decimal) |
NA | NA | NA (integer) |
Example
In this example, the round(X;Y)
function returns the value of the
dewptm
(X
) rounded to the nearest multiple of
Y
, which is 1
, on the
pub.demo.weather.wunderground.observed_hourly
table.
<base table="pub.demo.weather.wunderground.observed_hourly"/> <colord cols="zipcode, date, tempm, dewptm"/> <willbe name="round_dewptm" value="round(dewptm;1)"/>
Example
In the following example,
round(X;Y)
rounds the time in
tme
(X
) into 10-minute
intervals (Y
is '00:10:00'
) in the
pub.doc.retail.salesdetail
table for a
specific store and date. Note that Y
is written as
a string (single quotes) and the time format is
hms24
(24-hour).
<note type="base">Applied to table: pub.doc.retail.salesdetail</note>
<base table="pub.doc.retail.salesdetail"/>
<sel value="(store=3)"/>
<sel value="(trans_date=20150112)"/>
<willbe name="interval" value="round(tme;'00:10:00')" format="type:hms24"/>
<colord cols="date, tme, xsales, interval"/>
You can then perform a tabulation to find the total sales for each 10-minute interval.
<tabu label="Tabulation on Sales Detail" breaks="interval">
<tcol source="xsales" fun="sum" label="Sum of`Extended`Sales"/>
</tabu>