round number to the first 3 digits (start with digit != 0)

丶灬走出姿态 提交于 2019-12-01 15:00:48

问题


is there a predefined format-function that rounds a number to the first 3 digits? (The start should be a numbers != 0)

-0.02528498    to -0.0253
 1.857403      to 1.86     
 2060943       to 2060000
 0.00006513832 to 0.0000651

回答1:


You can use the function signif:

signif(-0.02528498, 3)
# [1] -0.0253
signif(1.857403, 3)
# [1] 1.86
signif(2060943, 3)
# [1] 2060000
signif(0.00006513832, 3)
# [1] 0.0000651


来源:https://stackoverflow.com/questions/29674349/round-number-to-the-first-3-digits-start-with-digit-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!