I believe if you use something like "%015.8lf" you will get more of what you
want.
I always think that the .8 is the number of digits to the right of decimal
and the 15
is the entire field width (including sign, any leading zero digits, any
digits to the left
of the decimal, the decimal point, and digits to the right of decimal
point). For
example:
double pi(3.141592);
format a("%015.8lf");
a % pi;
printf("%s\n",a.str().c_str());
prints:
000003.14159200
Larry
----- Original Message -----
From: "alfC"
I always found the rules for printf formatting, which Boost.Format uses, cryptic. I usually find the right combination by trial and error. In this case I want to print decimal numbers with both fixed number of integer digits and decimal digits. How can I do this with Boost.Format.
#include
#include<iostream> int main(){ int i = 2; std::cout << boost::format("%04i") % i << std::endl; //prints 0002, ok! double d = 3.1415; std::cout<< boost::format("%04.8f") % d << std::endl; // ^ prints 3.14150000, // want 0003.14150000 //(or even ' 3.14150000') //(or even ' 3.1415 ') return 0; } Thank you, Alfredo
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users