This function takes a numeric vector or a single numeric value and formats it to a specified number of decimal places. The function returns a character vector with the numbers formatted as strings.

zround(x, digits = 2, method = 1)

Arguments

x

A numeric vector or a single numeric value.

digits

An integer indicating the number of decimal places to format the numbers. Defaults to 2.

method

An integer (1 or 2) specifying the rounding method:

Value

A character vector with each number in x formatted to digits decimal places.

Examples

x = c(5.555, 1.115, -0.002)
zround(x, method = 1)
#> [1] "5.56" "1.11" "0.00"
zround(x, method = 2)
#> [1] "5.55"  "1.11"  "-0.00"
formatC(x, digits = 2, format = "f")
#> [1] "5.55"  "1.11"  "-0.00"
formattable::formattable(x, digits = 2, format = "f")
#> [1] 5.55  1.11  -0.00