Here’s a related topic.
I’m looking for something slightly different, I’m printing out a 4×4 floating point matrix. In fact I’m using this prettyprint method to do it, which will preclude me from using printf formatting which I’m a little more familiar with.
I can set ios_base::width() to set a minimum width to pad out the zeros and ones but the likes of 0.6666667 screws up the alignment. I figure I can set precision but it only affects the number of significant figures and not the total number of char’s produced by the value. I can’t seem to use unsetf on an ostream to set ‘default notation’… Even if I could do that I suspect a minus sign would mess up alignment anyway.
Is there a workaround?
My temporary solution is
width(7)andprecision(4). It gives me 4 digits after the decimal point and 3 which is space to put the minus sign, a single digit, and the decimal point. I have to check and modify width in order to accomodate (some of the) values larger than99.9999or less than-9.9999to preserve alignment. This has the benefit that567890123will not be printed as5678901, all it will do is throw off alignment (a lot, it will be printed as567890123.0000).