niceRound: Rounding to a Predictable Number of Digits

Description Usage Arguments Details Author(s) See Also


Rounds numbers to always have the specified number of decimal digits, rather than R's "greedy" most-compact rounding convention. Includes optional "<0.0..." override adequate for representing small p-values.


niceRound(numbers, digits = 0, plurb = FALSE)



the numbers to be rounded. Can also be a vector or numeric array.


the desired number of decimal digits


logical, should the p-value-style "less-than blurb" convention be used? Default FALSE.


R's standard round utility rounds to at most the number of digits specified. When the number happens to round more "compactly", it rounds to fewer digits. Thus, for example, round(4.03,digits=2) yields 4 as an answer. This is undesirable when trying to format a table, e.g., for publication.

niceRound solves this problem by wrapping a format call around the round call. The result will always have digits decimal digits. In addition, since reporting p-values always involves rounding, if the argument plurb is TRUE, then values below the rounding thresholds will be represented using the "less than" convention. For example, with digits=3 and plurb=TRUE, the number 0.0004 will be represented as <0.001.


Assaf P. Oron <>

See Also


table1xls documentation built on May 2, 2019, 5:54 a.m.