Convert numbers to cardinal character vectors (one, two, three)

cardinal(
x,
max_n = get_config("nombre::max_n", Inf),
negative = get_config("nombre::negative", "negative"),
...
)

nom_card(
x,
max_n = get_config("nombre::max_n", Inf),
negative = get_config("nombre::negative", "negative"),
...
)

Arguments

x A numeric vector A numeric vector. When the absolute value of x is greater than max_n, x remains numeric instead of being converted to words. If max_n is negative, no xs will be converted to words. (This can be useful when max_n is passed by another function.) Defaults to Inf, which converts all xs to words. Default can be changed with set_config("nombre::max_n"). A character vector to append to negative numbers. Defaults to "negative". Default can be changed with set_config("nombre::negative"). Additional arguments passed to fracture::frac_mat(). See details.

Value

A character vector of the same length as x

Fractions:

Decimal components of x are automatically converted to fractions by fracture::frac_mat(). Named arguments of cardinal() and nom_card() are passed to fracture::frac_mat() through .... Helpful arguments include:

• base_10 = TRUE, which forces all fractions to use denominators that are powers of ten

• common_denom = TRUE, which forces all fractions to use the least common denominator when x is a vector

• max_denom, which sets the maximum allowable denominator. By default, the maximum denominator is "ten-millionths".

uncardinal() to convert character vectors to numbers

Other number names: adverbial(), collective(), denominator(), numerator(), ordinal()

Examples

nom_card(2)
#> [1] "two"nom_card(1:10)
#>  [1] "one"   "two"   "three" "four"  "five"  "six"   "seven" "eight" "nine"
#> [10] "ten"  nom_card(2 + 4/9)
#> [1] "two and four ninths"nom_card(-2)
#> [1] "negative two"nom_card(-2, negative = "minus")
#> [1] "minus two"
nom_card(5:15, max_n = 10)
#>  [1] "five"  "six"   "seven" "eight" "nine"  "ten"   "11"    "12"    "13"
#> [10] "14"    "15"
paste("There are", nom_card(525600), "minutes in a year.")
#> [1] "There are five hundred twenty-five thousand six hundred minutes in a year."paste("There are", nom_card(3.72e13), "cells in the human body.")
#> [1] "There are thirty-seven trillion two hundred billion cells in the human body."
nom_card(1 / 2^(1:4))
#> [1] "one half"      "one quarter"   "one eighth"    "one sixteenth"nom_card(1 / 2^(1:4), common_denom = TRUE)
#> [1] "eight sixteenths" "four sixteenths"  "two sixteenths"   "one sixteenth"   nom_card(1 / 2^(1:4), base_10 = TRUE)
#> [1] "five tenths"
#> [2] "twenty-five hundredths"
#> [3] "one hundred twenty-five thousandths"
#> [4] "six hundred twenty-five ten-thousandths"nom_card(1 / 2^(1:4), base_10 = TRUE, common_denom = TRUE)
#> [1] "five thousand ten-thousandths"
#> [2] "two thousand five hundred ten-thousandths"
#> [3] "one thousand two hundred fifty ten-thousandths"
#> [4] "six hundred twenty-five ten-thousandths"
nom_card(1 / 2:5)
#> [1] "one half"    "one third"   "one quarter" "one fifth"  nom_card(1 / 2:5, base_10 = TRUE)
#> [1] "five tenths"
#> [2] "three million three hundred thirty-three thousand three hundred thirty-three ten-millionths"
#> [3] "twenty-five hundredths"
#> [4] "two tenths"                                                                                 nom_card(1 / 2:5, base_10 = TRUE, max_denom = 100)
#> [1] "five tenths"             "thirty-three hundredths"
#> [3] "twenty-five hundredths"  "two tenths"