Rounds a numeric value to a specified number of decimal places and formats it to always show the specified number of decimal places, including trailing zeros.

custom_round(x, digits = 1)

Arguments

x

A numeric vector to be rounded and formatted.

digits

An integer indicating the number of decimal places to round to. Defaults to 1.

Value

A character vector with the rounded and formatted numbers.

Examples

custom_round(3.14159)      # "3.1"
#> [1] "3.1"
custom_round(3.14159, 3)   # "3.142"
#> [1] "3.142"
custom_round(c(2, 2.5), 2) # "2.00" "2.50"
#> [1] "2.00" "2.50"