This function is used within format_value to prepare numeric values within
cells for formatting and display.
Usage
round_fmt(x, digits, na_str = "NA")
Value
A character value representing the value after rounding, containing
containing any trailling zeros required to display exactly
digits
elements.
Arguments
x
numeric(1). Value to format
digits
numeric(1). Number of digits to round to, or NA to convert to a
character value with no rounding.
na_str
character(1). The value to return if x is NA.
Details
This function combines the rounding behavior of R's standards-complaint
round function (see the Details section of that documentation)
with the strict decimal display of sprintf. The exact behavior
is as follows:
If x is NA, the value of na_str is returned
If x is non-NA but digits is NA, x is converted to a character
and returned
If x and digits are both non-NA, round is called first,
and then sprintf is used to convert the rounded value to a character with the
appropriate number of trailing zeros enforced.