Pre {Line-Height: 1; color: #9f1d66; Background-color: # d2d2d2; font-size: 16px ;}. sysfunc {color: # 5d57ff; font-style: italic; font-weight: bold ;}. selffuc {color: #8e0ed3 ;}. bool {color: #008000 ;}. condition {color: #008000; font-weight: bold ;}. key {color: #440080 ;}. vaR {color: #008000; font-style: italic ;}. digit {color: #000080; font-weight: bold ;}. includepre {color: # 661d9f ;}. operator? {Color: # fd1a53; font-weight: bold ;}
SETF () Is the function for appending a flag, and flags () Is the function for setting a flag? The fixed flag displays floating-point numbers in the form of fixed points ??
When the fixed mark exists, it indicates that the data is output in a certain number of digits. Otherwise, after the fixed mark is removed, the data is output in the original position-that is, the last 0 of the decimal number is not displayed.
Therefore, there are two scenarios:
(1) In-situ output, the fixed mark should be removed :? Cout. Unsetf (IOs: fixed)
?????? For example, 0.1? The output is 0.1?
(2) set the number of output digits after the decimal point
????????? Take two steps :?????????????????????? Step 1 ---------??? Set positioning output? Cout. SETF (IOs: fixed )??????????????????????? Step 2 ---------??? Set output precision? Cout. Precision (4 )??
As shown in the following program:
??
???? # Include? <Iostream. h> ?????? # Include? <Iomanip. h> ?????? Void? Main (void )?????? {?????? Cout. SETF (IOs: fixed );?????? Cout <setprecision (2) <(float) 0.1 <Endl; // output 0.10 ?????? Cout. unsetf (IOs: fixed );?????? Cout <setprecision (2) <(float) 0.1 <Endl ;? // Output 0.1 ??????}????????? Fout <RS <'/t' <dr_mean <"(";???????????? Fout. SETF (IOs: fixed );????????????? Fout <dr_sd <")" <Endl ;???????????? Fout. unsetf (IOs: fixed );????????????? Fout <'/t' <mature_mean <"(";???????????? Fout. SETF (IOs: fixed );?????? Fout. Precision (4 );???????????????????????? Fout <mature_sd <")" <Endl ;???????????? Fout. unsetf (IOs: fixed );????????????? Fout <'/t' <cost_mean <"(";?????????????????? Fout. SETF (IOs: fixed );?????? Fout. Precision (6 );??????????????????? Fout <cost_sd <")" <Endl ;????????????? Fout. unsetf (IOs: fixed );???
The output result is as follows:
0.998836 --- In-situ? (0.000000) --- six
2746.2 --- In-Situ
(99.7445) -- four digits
3.152 -- In-Situ
(0.015522) -- six
Used in this article? Calligraphy and painting novel software? Released, the content has nothing to do with the software, and the painting and calligraphy novel software? More comfortable reading, more comfortable writing, and easier Publishing.
How can I control the output precision of decimal points ?. XML