There is a caveat that setting the .precision() and the stream flags std::fixed and std::showpoint, etc.. will modify the stream flags as indicated by @dxiv in his now deleted answer and modify the stream behavior program-wide. That is important and can have program wide implications regardless where they are set.
Often you want to change the format for a limited purpose, such as for all floating point output in a class overload of <<, or the "code block" as your title indicates, etc... If you make the change in the overloaded member function, it affects std::cout throughout the rest your program -- which may not have been intended.
C++ provides a simple mechanism to make the change on a temporary basis by saving the stream .flags() before adjusting the stream and then when done, restoring the original flags before you leave the scope where the changes were desired. This will undo the std::ios_base::fmtflags, e.g. std::fixed and std::showpoint settings, but the .precision() change must be undone by restoring the default value of 6.
To save the stream flags before making changes you can use:
std::ios_base::fmtflags f = std::cout.flags(); /* save format flags */
When done with the output requiring the change you can restore the flags with:
std::cout.flags(f); /* restore saved flags */
Restoring the default .precision() takes setting the precision back to the default 6, e.g.
std::cout.precision(6); /* restore precision */
There are two (actually three) ways to set the format flags. (1) You can use, e.g. std::fixed, std::showpoint, etc.. individually or (2,3) you can manipulate the flags directly using std::ios_base::setf or by declaring BitmaskType std::ios_base::fmtflags. To set the std::fixed and std::showpoint flags directly, you can do:
std::cout.setf (std::ios_base::fixed, std::ios_base::showpoint);
To use the BitmaskType you would create an instance of the type and the set the value by OR'ing and AND'ing values for the wanted flags. The .flags() member function is then used to set the flag values, in the same manner you pass the saved format flags to undue the changes you have made using the saved bitmap of the original flags state. The std::ios_base::fmtflags link above provides an example of each of the ways.
Saving before the change and then restoring the flags when done resets the flags regardless of which method you used to set them.