Formatting Decimal places in R

前端 未结 12 2067
忘了有多久
忘了有多久 2020-11-22 01:42

I have a number, for example 1.128347132904321674821 that I would like to show as only two decimal places when output to screen (or written to a file). How does one do that?

12条回答
  •  礼貌的吻别
    2020-11-22 01:58

    If you prefer significant digits to fixed digits then, the signif command might be useful:

    > signif(1.12345, digits = 3)
    [1] 1.12
    > signif(12.12345, digits = 3)
    [1] 12.1
    > signif(12345.12345, digits = 3)
    [1] 12300
    

提交回复
热议问题