Help in C++ with cout.precision(); and cout.setf(ios::fixed | ios::showpoint)

Saint Nick

Lifer
Jan 21, 2005
17,722
6
81
The output needs to look like this:

log(3.14) = 1.1447
log10(3.14) = 0.4971

same goes for the rest of the functions. the actual result of the calculations should have four digits to the right of the decimal point. i can't figure out how to do it with what i have.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
The default format for floating point output is general - in this format precision() specifies the total number of digits displayed.

Set your format to fixed (with setf()) - now precision() specifies the number of digits to the right of the decimal place.

Precisely formatted stream output can be a PITA - sometimes it's just easier to drop back to printf