Rounds to digits decimal places and prints them all, trailing zeros
included – fmt_round(2.5, 2) is "2.50", not "2.5".
These format numbers in a data frame or vector before a table is
built; the fmt_* functions as_rtftables()'s cell_format takes
(fmt_count_pct(), ...) format cells as the table is built.
Arguments
- x
A numeric vector. Character input is an error – character columns are taken as already formatted.
- digits
Decimal places. Default
2.- rounding
"r"rounds withbase::round(), which is banker's rounding;"sas"rounds half away from zero as SAS does. They differ on exact halves –23.445is"23.44"under"r"and"23.45"under"sas".NULL, the default, readsgetOption("rtfreporter.rounding")("r"unless set); seeround_num().- na
Text for
NAandNaN. Default""(an empty cell, which is how rtfreporter renders a missing value anyway).
Examples
fmt_round(c(2.5, 20.333, 100), digits = 2)
#> [1] "2.50" "20.33" "100.00"
fmt_round(23.445, digits = 2) # "23.44" -- banker's
#> [1] "23.44"
fmt_round(23.445, digits = 2, rounding = "sas") # "23.45"
#> [1] "23.45"