Learn R Programming

berryFunctions (version 1.22.5)

round0: 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,
  ...
)

Value

Character string vector

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".

Author

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

See Also

Examples

Run this code
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

Run the code above in your browser using DataLab