bigfloat_friendly {friendlynumber} | R Documentation |
Translate a bigfloat to a cardinal character vector
Description
Convert a <bignum_bigfloat>
to a cardinal numeral (e.g. one tenth, one, two).
A bignum::bigfloat()
can store numbers with up to 50 decimal digits of
precision, which is useful for manipulating numbers which can't be accurately
represented in a <numeric>
vector.
bigfloat_friendly_safe()
checks that all arguments are of the correct type
and raises an informative error otherwise. bigfloat_friendly()
does not
perform input validation to maximize its speed.
Usage
bigfloat_friendly(
numbers,
zero = "zero",
na = "missing",
nan = "not a number",
inf = "infinity",
negative = "negative ",
decimal = " and ",
and = FALSE,
hyphenate = TRUE,
and_fractional = and,
hyphenate_fractional = hyphenate,
english_fractions = NULL
)
bigfloat_friendly_safe(
numbers,
zero = "zero",
na = "missing",
nan = "not a number",
inf = "infinity",
negative = "negative ",
decimal = " and ",
and = FALSE,
hyphenate = TRUE,
and_fractional = and,
hyphenate_fractional = hyphenate,
english_fractions = NULL
)
Arguments
numbers |
A |
zero |
What to call values of |
na |
What to call values of |
nan |
What to call values of |
inf |
What to call values of |
negative |
A prefix added to the translation of negative elements of |
decimal |
A word inserted between the whole and fractional part of translated
|
and |
Whether to insert an |
hyphenate |
Whether to hyphenate numbers 21 through 99 (e.g. |
and_fractional |
Whether to insert an
|
hyphenate_fractional |
Whether to hyphenate numbers 21 through 99 in the fractional part of translated
|
english_fractions |
A named character vector used as a dictionary for the translation of the
fractional part of For example By default Provide an empty character to |
Value
A non-NA character vector of the same length as numbers
.
Examples
bigfloat_friendly(bignum::bigfloat(c(0.5, 0, 0.123, NA, NaN, Inf)))
# Specify the translations of "special" numbers
bigfloat_friendly(bignum::bigfloat(NaN), nan = "NAN")
# Modify the output formatting
big <- bignum::bigfloat(1234.5678)
bigfloat_friendly(big)
bigfloat_friendly(big, decimal = " point ")
bigfloat_friendly(big, hyphenate_fractional = FALSE)
bigfloat_friendly(big, and = TRUE, and_fractional = TRUE, decimal = " . ")
# The `friendlynumber.bigfloat.digits` option specifies the number of
# `<bignum_bigfloat>` digits mentioned by `bigfloat_friendly()`
opts <- options()
options(friendlynumber.bigfloat.digits = 5)
bigfloat_friendly(bignum::bigpi)
options(friendlynumber.bigfloat.digits = 10)
bigfloat_friendly(bignum::bigpi)
options(opts)
# Set `english_fractions` to specify the translation of certain
# fractions. The names (keys) of `english_fractions` should match
# the decimal part of a fraction (e.g. `"04"` matches `0.04`).
bigfloat_friendly(
bignum::bigfloat(c(1/2, 0.04, 1.5, 10)),
english_fractions = c(`5` = "1/2", `04` = "4/100")
)
# Input validation
try(bigfloat_friendly_safe(bignum::bigpi, and = NA))