是否可以对数字进行舍入(根据条件删除指数)。例子
> paste0(as.character(as.numeric(0.00000044854548)), "%")
[1] "4.4854548e-07%"
> paste0(as.character(as.numeric(0.44854548)), "%")
[1] "0.44854548%"
````
expected output (basically stick to 4 non-zero numbers), if it the number is 0.00000044854548, then "0.0000004485%". If the number is 0.44854548, then "0.4485%"
````
> paste0(as.character(as.numeric(0.00000044854548)), "%")
[1] "0.0000004485%"
> paste0(as.character(as.numeric(0.44854548)), "%")
[1] "0.4485%"
````
答案 0 :(得分:0)
您可以使用formatC
。
paste0(formatC(0.00000044854548, format="fg", digits=4), "%")
# [1] "0.0000004485%"
paste0(formatC(0.44854548, format="fg", digits=4), "%")
# [1] "0.4485%"