Convert integer to words

前端 未结 2 848
说谎
说谎 2020-12-04 03:12

For the purpose of styling data visualizations, I\'d like to be able to display an integer using words (e.g.

\"Two thousand and seventeen\"

2条回答
  •  旧巷少年郎
    2020-12-04 03:55

    Asides from the function I linked in the comments, here's another solution from a GitHub gist:

    source("https://gist.githubusercontent.com/hack-r/22104543e2151519c41a8f0ce042b31c/raw/01731f3176b4ee471785639533d38eda4790ab77/numbers2words.r")
    
    numbers2words(0)
    

    [1] "zero"

    numbers2words(5)
    

    [1] "five"

    numbers2words(50000)
    

    [1] "fifty thousand"

    numbers2words(50000000000000)
    

    [1] "fifty trillion"

提交回复
热议问题