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

cardinal(x, max_n = Inf, negative = "negative", ...)

nom_card(x, max_n = Inf, negative = "negative", ...)

## Arguments

x

A numeric vector

max_n

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.

negative

A character vector to append to negative numbers. Defaults to "negative".

...

Arguments passed on to fracture::frac_mat

denom

If denom is not NULL, all fractions will have a denominator of denom. This will ignore all other arguments that affect the denominator.

base_10

If TRUE, all denominators will be a power of 10.

common_denom

If TRUE, all fractions will have the same denominator.

If the least common denominator is greater than max_denom, max_denom is used.

max_denom

All denominators will be less than or equal to max_denom.

If base_10 is TRUE, the maximum denominator will be the largest power of 10 less than max_denom.

A max_denom greater than the inverse square root of machine double epsilon will produce a warning because floating point rounding errors can occur when denominators grow too large.

## Value

A character vector of the same length as x

## Fractions

Decimal components of x are automatically converted to fractions by fracture::frac_mat().

uncardinal() to convert character vectors to numbers

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

## Examples

nom_card(2)
#>  "two"
nom_card(1:10)
#>   "one"   "two"   "three" "four"  "five"  "six"   "seven" "eight" "nine"
#>  "ten"
nom_card(2 + 4/9)
#>  "two and four ninths"
nom_card(-2)
#>  "negative two"
nom_card(-2, negative = "minus")
#>  "minus two"

nom_card(5:15, max_n = 10)
#>   "five"  "six"   "seven" "eight" "nine"  "ten"   "11"    "12"    "13"
#>  "14"    "15"

paste("There are", nom_card(525600), "minutes in a year.")
#>  "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.")
#>  "There are thirty-seven trillion two hundred billion cells in the human body."

nom_card(1 / 2^(1:4))
#>  "one half"      "one quarter"   "one eighth"    "one sixteenth"
nom_card(1 / 2^(1:4), common_denom = TRUE)
#>  "eight sixteenths" "four sixteenths"  "two sixteenths"   "one sixteenth"
nom_card(1 / 2^(1:4), base_10 = TRUE)
#>  "five tenths"
#>  "twenty-five hundredths"
#>  "one hundred twenty-five thousandths"
#>  "six hundred twenty-five ten-thousandths"
nom_card(1 / 2^(1:4), base_10 = TRUE, common_denom = TRUE)
#>  "five thousand ten-thousandths"
#>  "two thousand five hundred ten-thousandths"
#>  "one thousand two hundred fifty ten-thousandths"
#>  "six hundred twenty-five ten-thousandths"

nom_card(1 / 2:5)
#>  "one half"    "one third"   "one quarter" "one fifth"
nom_card(1 / 2:5, base_10 = TRUE)
#>  "five tenths"
#>  "three million three hundred thirty-three thousand three hundred thirty-three ten-millionths"
#>  "twenty-five hundredths"
#>  "two tenths"
nom_card(1 / 2:5, base_10 = TRUE, max_denom = 100)
#>  "five tenths"             "thirty-three hundredths"
#>  "twenty-five hundredths"  "two tenths"