| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/string.R |
| 3 |
\name{numbers_to_words} |
| 4 |
\alias{numbers_to_words} |
| 5 |
\alias{n2w} |
| 6 |
\title{Convert numbers to English words} |
| 7 |
\usage{ |
| 8 |
numbers_to_words(x, cap = FALSE, hyphen = TRUE, and = FALSE) |
| 9 |
|
| 10 |
n2w(x, cap = FALSE, hyphen = TRUE, and = FALSE) |
| 11 |
} |
| 12 |
\arguments{ |
| 13 |
\item{x}{A numeric vector. The absolute values should be less than \code{1e15}.} |
| 14 |
|
| 15 |
\item{cap}{Whether to capitalize the first letter of the word. This can be |
| 16 |
useful when the word is at the beginning of a sentence. Default is \code{FALSE}.} |
| 17 |
|
| 18 |
\item{hyphen}{Whether to insert hyphen (-) when the number is between 21 and |
| 19 |
99 (except 30, 40, etc.).} |
| 20 |
|
| 21 |
\item{and}{Whether to insert \code{and} between hundreds and tens, e.g., write 110 |
| 22 |
as \dQuote{one hundred and ten} if \code{TRUE} instead of \dQuote{one hundred |
| 23 |
ten}.} |
| 24 |
} |
| 25 |
\value{ |
| 26 |
A character vector. |
| 27 |
} |
| 28 |
\description{ |
| 29 |
This can be helpful when writing reports with \pkg{knitr}/\pkg{rmarkdown} if |
| 30 |
we want to print numbers as English words in the output. The function \code{n2w()} |
| 31 |
is an alias of \code{numbers_to_words()}. |
| 32 |
} |
| 33 |
\examples{ |
| 34 |
library(xfun) |
| 35 |
n2w(0, cap = TRUE) |
| 36 |
n2w(0:121, and = TRUE) |
| 37 |
n2w(1e+06) |
| 38 |
n2w(1e+11 + 12345678) |
| 39 |
n2w(-987654321) |
| 40 |
n2w(1e+15 - 1) |
| 41 |
n2w(123.456) |
| 42 |
n2w(123.45678901) |
| 43 |
n2w(123.456789098765) |
| 44 |
} |
| 45 |
\author{ |
| 46 |
Daijiang Li |
| 47 |
} |