numbers_to_words: Convert numbers to English words

Description Usage Arguments Value Author(s) Examples

View source: R/string.R

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

1
2
3
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

1
2
3
4
5
6
7
library(xfun)
n2w(0, cap = TRUE)
n2w(0:121, and = TRUE)
n2w(1e+06)
n2w(1e+11 + 12345678)
n2w(-987654321)
n2w(1e+15 - 1)

Example output

Attaching package: 'xfun'

The following object is masked from 'package:base':

    attr

[1] "Zero"
  [1] "zero"                       "one"                       
  [3] "two"                        "three"                     
  [5] "four"                       "five"                      
  [7] "six"                        "seven"                     
  [9] "eight"                      "nine"                      
 [11] "ten"                        "eleven"                    
 [13] "twelve"                     "thirteen"                  
 [15] "fourteen"                   "fifteen"                   
 [17] "sixteen"                    "seventeen"                 
 [19] "eighteen"                   "nineteen"                  
 [21] "twenty"                     "twenty-one"                
 [23] "twenty-two"                 "twenty-three"              
 [25] "twenty-four"                "twenty-five"               
 [27] "twenty-six"                 "twenty-seven"              
 [29] "twenty-eight"               "twenty-nine"               
 [31] "thirty"                     "thirty-one"                
 [33] "thirty-two"                 "thirty-three"              
 [35] "thirty-four"                "thirty-five"               
 [37] "thirty-six"                 "thirty-seven"              
 [39] "thirty-eight"               "thirty-nine"               
 [41] "forty"                      "forty-one"                 
 [43] "forty-two"                  "forty-three"               
 [45] "forty-four"                 "forty-five"                
 [47] "forty-six"                  "forty-seven"               
 [49] "forty-eight"                "forty-nine"                
 [51] "fifty"                      "fifty-one"                 
 [53] "fifty-two"                  "fifty-three"               
 [55] "fifty-four"                 "fifty-five"                
 [57] "fifty-six"                  "fifty-seven"               
 [59] "fifty-eight"                "fifty-nine"                
 [61] "sixty"                      "sixty-one"                 
 [63] "sixty-two"                  "sixty-three"               
 [65] "sixty-four"                 "sixty-five"                
 [67] "sixty-six"                  "sixty-seven"               
 [69] "sixty-eight"                "sixty-nine"                
 [71] "seventy"                    "seventy-one"               
 [73] "seventy-two"                "seventy-three"             
 [75] "seventy-four"               "seventy-five"              
 [77] "seventy-six"                "seventy-seven"             
 [79] "seventy-eight"              "seventy-nine"              
 [81] "eighty"                     "eighty-one"                
 [83] "eighty-two"                 "eighty-three"              
 [85] "eighty-four"                "eighty-five"               
 [87] "eighty-six"                 "eighty-seven"              
 [89] "eighty-eight"               "eighty-nine"               
 [91] "ninety"                     "ninety-one"                
 [93] "ninety-two"                 "ninety-three"              
 [95] "ninety-four"                "ninety-five"               
 [97] "ninety-six"                 "ninety-seven"              
 [99] "ninety-eight"               "ninety-nine"               
[101] "one hundred"                "one hundred and one"       
[103] "one hundred and two"        "one hundred and three"     
[105] "one hundred and four"       "one hundred and five"      
[107] "one hundred and six"        "one hundred and seven"     
[109] "one hundred and eight"      "one hundred and nine"      
[111] "one hundred and ten"        "one hundred and eleven"    
[113] "one hundred and twelve"     "one hundred and thirteen"  
[115] "one hundred and fourteen"   "one hundred and fifteen"   
[117] "one hundred and sixteen"    "one hundred and seventeen" 
[119] "one hundred and eighteen"   "one hundred and nineteen"  
[121] "one hundred and twenty"     "one hundred and twenty-one"
[1] "one million"
[1] "one hundred billion, twelve million, three hundred forty-five thousand, six hundred seventy-eight"
[1] "minus nine hundred eighty-seven million, six hundred fifty-four thousand, three hundred twenty-one"
[1] "nine hundred ninety-nine trillion, nine hundred ninety-nine billion, nine hundred ninety-nine million, nine hundred ninety-nine thousand, nine hundred ninety-nine"

xfun documentation built on June 16, 2021, 1:07 a.m.