Format number in R with both comma thousands separator and specified decimals

前端 未结 3 1960
刺人心
刺人心 2020-12-01 13:40

I\'d like to format numbers with both thousands separator and specifying the number of decimals. I know how to do these separately, but not together.

For example, I

相关标签:
3条回答
  • 2020-12-01 14:18

    formattable provides comma:

    library(formattable)
    
    comma(1000.64, digits = 1) # 1,000.6
    

    comma provides an elementary interface to formatC.

    0 讨论(0)
  • 2020-12-01 14:29
    formatC(1000.64, format="f", big.mark=",", digits=1)
    

    (sorry if i'm missing something.)

    0 讨论(0)
  • 2020-12-01 14:36

    format not formatC:

    format(round(as.numeric(1000.64), 1), nsmall=1, big.mark=",") # 1,000.6

    0 讨论(0)
提交回复
热议问题