Aliases: format.info
Keywords: character print programming
### ** Examples dd <- options("digits") ; options(digits = 7) #-- for the following format.info(123) # 3 0 0
[1] 3 0 0
format.info(pi) # 8 6 0
[1] 8 6 0
format.info(1e8) # 5 0 1 - exponential "1e+08"
[1] 5 0 1
format.info(1e222) # 6 0 2 - exponential "1e+222"
[1] 6 0 2
x <- pi*10^c(-10,-2,0:2,8,20) names(x) <- formatC(x, width = 1, digits = 3, format = "g") cbind(sapply(x, format))
[,1] 3.14e-10 "3.141593e-10" 0.0314 "0.03141593" 3.14 "3.141593" 31.4 "31.41593" 314 "314.1593" 3.14e+08 "314159265" 3.14e+20 "3.141593e+20"
t(sapply(x, format.info))
[,1] [,2] [,3] 3.14e-10 12 6 1 0.0314 10 8 0 3.14 8 6 0 31.4 8 5 0 314 8 4 0 3.14e+08 9 0 0 3.14e+20 12 6 1
## using at least 8 digits right of "." t(sapply(x, format.info, nsmall = 8))
[,1] [,2] [,3] 3.14e-10 12 6 1 0.0314 10 8 0 3.14 10 8 0 31.4 11 8 0 314 12 8 0 3.14e+08 18 8 0 3.14e+20 12 6 1
# Reset old options: options(dd)