round0 {berryFunctions}R Documentation

Round numbers with leading and trailing zeros

Description

Round numbers and add leading + trailing zeros

Usage

round0(
  x,
  digits = 0,
  pre = 2,
  width = digits + pre + ifelse(digits == 0, 0, 1),
  flag = 0,
  ...
)

Arguments

x

Value(s)

digits

Number of digits (after decimal separator) to keep. DEFAULT: 0

pre

Minimum number of characters before the decimal separator. DEFAULT: 2

width

Total width (number of characters including dot). DEFAULT: digits+pre (+1 if needed)

flag

Flag. Could be "" for spaces. DEFAULT: "0"

...

Further arguments passed to formatC, except for "format".

Value

Character string vector

Author(s)

Berry Boessenkool, berry-b@gmx.de, Jun 2017

See Also

formatC, sprintf

Examples

round0( pi*10^(-3:5), 2)
stopifnot(round0(17.3, 2) == "17.30")
round0(7.3)
round0(c(7.3,777.1234), 2)
round0(c(0.2,7.3,12.8), 2, pre=1)
round0(c(0.2,7.3,12.8), 1, pre=3, flag="") # spaces instead of zeros


[Package berryFunctions version 1.20.1 Index]