Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

numbers_to_words

Convert numbers to English words


Description

This can be helpful when writing reports with knitr/rmarkdown if we want to print numbers as English words in the output. The function n2w() is an alias of numbers_to_words().

Usage

numbers_to_words(x, cap = FALSE, hyphen = TRUE, and = FALSE)

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

Arguments

x

A numeric vector. Values should be integers. The absolute values should be less than 1e15.

cap

Whether to capitalize the first letter of the word. This can be useful when the word is at the beginning of a sentence. Default is FALSE.

hyphen

Whether to insert hyphen (-) when the number is between 21 and 99 (except 30, 40, etc.).

and

Whether to insert and between hundreds and tens, e.g., write 110 as “one hundred and ten” if TRUE instead of “one hundred ten”.

Value

A character vector.

Author(s)

Daijiang Li

Examples

library(xfun)
n2w(0, cap = TRUE)
n2w(0:121, and = TRUE)
n2w(1e+06)
n2w(1e+11 + 12345678)
n2w(-987654321)
n2w(1e+15 - 1)

xfun

Miscellaneous Functions to Support Packages Maintained by 'Yihui Xie'

v0.22
MIT + file LICENSE
Authors
Yihui Xie [aut, cre, cph] (<https://orcid.org/0000-0003-0645-5666>), Wush Wu [ctb], Daijiang Li [ctb], Xianying Tan [ctb], Salim Brüggemann [ctb] (<https://orcid.org/0000-0002-5329-5987>), Christophe Dervieux [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.