You can always go on a different route:
# next line is really one line wrapped here R> cppFunction('std::string ben(double val) { char buf[32]; \ snprintf(buf, 31, "%15.15f", val);\ return std::string(buf); }') R> ben(1/3) [1] "0.333333333333333" R> ben(1e6/3) [1] "333333.333333333313931" R> ben(1e12/3) [1] "333333333333.333312988281250" R>
And in the meantime, @Manetheran also showed you the standard iomanip route.
And of course there is Rprintf() .
#
Oh, and for the record, they also work with your desired input:
R> ben(1) [1] "1.000000000000000" R> ben2(1) 1.000000000000000 R>
Dirk eddelbuettel
source share