force_decimals: Force printing a specified number of decimals for a number

View source: R/print_decimals_specified.R

force_decimalsR Documentation

Force printing a specified number of decimals for a number

Description

Force printing a specified number of decimals for a number

Usage

force_decimals(x, decimals = 2, round_zero = TRUE)

Arguments

x

the numeric values to be printed

decimals

how many decimals are to be printed. Defaults to 2.

round_zero

whether small values should be rounded to zero or whether they should be displayed as e.g. < .01. See details. Defaults to TRUE.

Details

By default, force_decimals() will round numbers that are small enough down to zero, e.g., 0.0004 will be rounded to 0.00. If round_zero = FALSE, force_decimals(0.0004) will return "< 0.01" instead. See examples.

Value

Character vector of length length(x). The number(s) in the required format.

Author(s)

Martin Papenberg martin.papenberg@hhu.de

Examples


force_decimals(c(1.23456, 0.873, 2.3456))
force_decimals(c(1.23456, 0.873, 2.3456), 3)

force_decimals(c(0.004, 0.001, 0.0005, 0.02))
force_decimals(c(0.004, 0.001, 0.0005, 0.02), round_zero = FALSE)
force_decimals(c(0.004, 0.001, 0.0005, 0.02), 3, round_zero = FALSE)


m-Py/prmisc documentation built on March 29, 2025, 2:30 p.m.