我正在读取一个文件,该文件的值具有指数值的7位精度
4.81591e-007 5.17968e-007 5.03954e-008 -8.30735e-007
4.81591e-007
5.17968e-007
5.03954e-008
-8.30735e-007
虽然我得到的值只有5点精度
0.000000 0.000001 0.000000 -0.000001 -0.000002
0.000000
0.000001
-0.000001
-0.000002
代码如下,是
#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { FILE *fp2; fp2=fopen("output","w"); int i=0; ifstream myFile; myFile.open("sruthi_DATA_.txt"); vectornumberlist; long double number; while(myFile >> number){ // numberlist.push_back(number); i++; } int j; for(j=0;j Martin York.. 5 尝试将值打印为 fixed http://www.cplusplus.com/reference/iomanip/setprecision/ http://www.cplusplus.com/reference/cstdio/printf/ std::cout << std::fixed << std::setprecision(10) << value << "\n"; 定义: fixed: the value is represented with exactly as many digits in the decimal part as specified by the precision field (precision) and with no exponent part. scientific: as many decimal digits as the precision field (precision). Finally, this notation always includes an exponential part consisting on the letter e followed by an optional sign and three exponential digits. 用于在C中打印: fprintf(fp2, "%.10f\n", value); 格式说明符的定义是: %[flags][width][.precision][length]specifier Precision: For a, A, e, E, f and F specifiers: this is the number of digits to be printed after the decimal point. 因此,要获得与C(%f)相同的C++格式,您需要使用std::fixed.1> Martin York..:尝试将值打印为 fixed http://www.cplusplus.com/reference/iomanip/setprecision/ http://www.cplusplus.com/reference/cstdio/printf/ std::cout << std::fixed << std::setprecision(10) << value << "\n"; 定义: fixed: the value is represented with exactly as many digits in the decimal part as specified by the precision field (precision) and with no exponent part. scientific: as many decimal digits as the precision field (precision). Finally, this notation always includes an exponential part consisting on the letter e followed by an optional sign and three exponential digits. 用于在C中打印: fprintf(fp2, "%.10f\n", value); 格式说明符的定义是: %[flags][width][.precision][length]specifier Precision: For a, A, e, E, f and F specifiers: this is the number of digits to be printed after the decimal point. 因此,要获得与C(%f)相同的C++格式,您需要使用std::fixed.
Martin York.. 5
尝试将值打印为 fixed
fixed
http://www.cplusplus.com/reference/iomanip/setprecision/ http://www.cplusplus.com/reference/cstdio/printf/
std::cout << std::fixed << std::setprecision(10) << value << "\n";
定义:
fixed: the value is represented with exactly as many digits in the decimal part as specified by the precision field (precision) and with no exponent part. scientific: as many decimal digits as the precision field (precision). Finally, this notation always includes an exponential part consisting on the letter e followed by an optional sign and three exponential digits.
用于在C中打印:
fprintf(fp2, "%.10f\n", value);
格式说明符的定义是:
%[flags][width][.precision][length]specifier Precision: For a, A, e, E, f and F specifiers: this is the number of digits to be printed after the decimal point.
因此,要获得与C(%f)相同的C++格式,您需要使用std::fixed.
std::fixed