DescTools (version 0.99.11)

RoundM: Round to Multiple

Description

Returns a number rounded to the desired multiple.

Usage

RoundM(x, multiple = 1, FUN = round)

Arguments

x
numeric. The value to round.
multiple
numeric. The multiple to which the number is to be rounded. Default is 1.
FUN
the rounding function as character or as expression. Can be one out of ceiling, round or floor. Default is round.

Value

  • the rounded value

Details

RoundM rounds up, away from zero, if the remainder of dividing number by multiple is greater than or equal to half the value of multiple if FUN is set to round. If FUN is ceiling it will always round up, and if FUN is floor it will always round down.

See Also

round, ceiling, floor

Examples

Run this code
RoundM(10, 3)     # Rounds 10 to a nearest multiple of 3 (9)
RoundM(-10, -3)   # Rounds -10 to a nearest multiple of -3 (-9)

RoundM(1.3, 0.2)  # Rounds 1.3 to a nearest multiple of 0.2 (1.2)
RoundM(5, -2)     # Returns an error, because -2 and 5 have different signs    

RoundM(c(1.92, 45.38, 0.831125), 0.05, ceiling)
RoundM(c(1.92, 45.38, 0.831125), 0.05, round)
RoundM(c(1.92, 45.38, 0.831125), 0.05, floor)

Run the code above in your browser using DataCamp Workspace