Learn R Programming

RastaRocket (version 1.0.2)

custom_round: Custom Round and Format

Description

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.

Usage

custom_round(x, digits = 1)

Value

A character vector with the rounded and formatted numbers.

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.

Examples

Run this code
RastaRocket::custom_round(3.14159)      # "3.1"
RastaRocket::custom_round(3.14159, 3)   # "3.142"
RastaRocket::custom_round(c(2, 2.5), 2) # "2.00" "2.50"

Run the code above in your browser using DataLab