我们收容,我们保护;我们失败,我们跑路;
一、打印数字
std::fixed
配合std::setprecision使用,设置显示浮点数值的有效数的数量
1 2 3
| std::cout << std::fixed << std::setprecision(10) << 10.120;
输出:10.1200000000
|
std::scientific 科学计数法
1 2 3
| std::cout << std::scientific << 10.120;
输出:1.0120000000e+01
|
std::hexfloat hex float
1 2 3
| std::cout << std::hexfloat << 10.120;
输出:0x1.43d70a3d71p+3
|
std::defaultfloat 默认
1 2 3
| std::cout << std::defaultfloat << 10.120;
输出:10.12
|
数字转字符串,并保留指定精度
1 2 3 4 5 6 7 8
| std::stringstream stream; stream << std::fixed << std::setprecision(10) << 10.120;
std::string str = stream.str();
输出:10.1200000000
|