Spell out numbers if they are smaller than ten
Usage
num_to_text(
number,
sentence_start = FALSE,
zero_or_no = "no",
uk_or_us = c("UK", "US"),
big_mark = ","
)Arguments
- number
Whole number(s) as
numericorinteger, to be turned into text. Numbers 0-10 (as well as 100 and 1000) are always written out in full, regardless of their place in the sentence. Numbers 11-1000 are written out in full if they are at the beginning of a sentence. Numbers greater than 1000 are returned as numerals, formatted withbig_mark. Negative numbers follow the same rules, with "minus" in front (e.g. "minus three"). Numbers with decimals are always returned as numerals. Can be a vector (e.g. a column indplyr::mutate()), in which case each number is turned into text; missing values stay missing.- sentence_start
Logical. If
TRUE, numbers up to 1000 are written out in full, and their first letter is capitalised.- zero_or_no
Specify what to print when the number is 0. Defaults to "no". Can be any string.
- uk_or_us
Defaults to UK which adds an "and" between "hundred" and other numbers (e.g. "One hundred and five"). If "US" is chosen, the "and" is removed (e.g. "One hundred five").
- big_mark
Defaults to "," (e.g. "1,999").
See also
Other verbaliseR functions:
listify(),
pluralise(),
prettify_date(),
restore_capitals()
Examples
num_to_text(3)
#> [1] "three"
num_to_text(333, sentence_start = TRUE)
#> [1] "Three hundred and thirty-three"
num_to_text(-3)
#> [1] "minus three"
num_to_text(c(0, 5, 50, 5000))
#> Warning: Numbers greater than 1000 are returned as numerals, regardless of their place
#> in the sentence.
#> [1] "no" "five" "50" "5,000"
