Reference > Methods
roundNearest(value,bucketSize)
Definition
Number roundNearest(Number value, Number bucketSize)
Description
Given the value and the bucket size, returns a Long that rounds to the closest multiple of the bucket size.
Parameter Definition
Name |
Type |
Description |
value |
Number |
Number to round |
bucketSize |
Number |
multiple, aka, bucket size to round to |
Examples
| Integer r1 = roundNearest(0,10); // r1 == 0
Integer r2 = roundNearest(3,10); // r2 == 0
Integer r3 = roundNearest(7,10); // r3 == 10
Integer r4 = roundNearest(14,10); // r4 == 10
Integer r5 = roundNearest(19,10); // r5 == 20
Integer r6 = roundNearest(20,10); // r6 == 20
Integer r7 = roundNearest(21,10); // r7 == 20
Integer r8 = roundNearest(239,60); // r8 == 240
Integer r9 = roundNearest(240,60); // r9 == 240
Integer r10 = roundNearest(241,60); // r10 == 240
|