num2char: Convert numbers to words

View source: R/utils2.R

num2charR Documentation

Convert numbers to words

Description

Convert whole or decimal numbers to word equivalent. N2W is equivalent to n2w/num2char but defaults to capitalizing the first word.

Usage

num2char(x, cap = FALSE, informal = FALSE, hyphen = TRUE, and = FALSE)

n2w(x, cap = FALSE, informal = FALSE, hyphen = TRUE, and = FALSE)

N2W(x, cap = TRUE, informal = FALSE, hyphen = TRUE, and = FALSE)

Arguments

x

numeric vector, less than '1e15'

cap

logical; if TRUE, capitalizes the first word

informal, and

logical; insert "and" between hundreds and tens

hyphen

logical; insert hyphen when the number is between 21 and 99 (except 30, 40, etc)

Details

Whole numbers twenty-one through ninety-nine are hyphenated when they are written out whether used alone or as part of a larger number; for example: "twenty-one" or "one million twenty-one."

Informal and formal case differ only by the use of "and" to separate 1-99: "one hundred one" is the formal case, and "one hundred and one" is the informal case.

References

http://dictionary.reference.com/help/faq/language/g80.html

https://www.grammarbook.com/numbers/numbers.asp

See Also

case; adapted from xfun::numbers_to_words

Examples

n2w(1e15 - 1)
n2w(0:121, and = TRUE)
n2w(123.456)
N2W(1e6)

x <- c(-1000, 100, 52052, 3922, 3012, 201, -152, 1002, 91070432)
cbind(x, informal = num2char(x, informal = TRUE), formal = num2char(x, FALSE))


raredd/rawr documentation built on Feb. 25, 2025, 1:48 p.m.