(x <- c(outer(c(1,pi), 10^(-10:11))))
sum(nchar(f1 <- format(x, digits=1))) # 220
sum(nchar(f2 <- sapply(x, format, digits=1)))# 194
sum(nchar(ff1<- formatN(x, sci=-1L))) # 152
sum(nchar(ff2<- formatN(x, sci=-2L))) # 150
sum(nchar(ff <- formatN(x))) # 150 .. the best
sum(nchar(ff3<- formatN(x, sci=-3L))) # 152
noquote(rbind(f1, f2, ff1, ff, ff2, ff3))
## the best is ff (where sci differs for neg.exp and pos.ex) - for this example
## the "extreme" formatting still keeps "95%" of numerical info :
stopifnot(all.equal(x, as.numeric(formatN(x)), tolerance = 0.05))
Run the code above in your browser using DataLab