//showpoint:展示小数点
//setbase(……)几进制
//setprecision(……)保留几位数字(有无std::cout << std::fixed;有区分)
#include <iomanip>
#include <iostream>
int main() {
double a = 3.1415926;//八位数字
double b = 1000.0;
double a1 = 3.1415926;
double b1 = 1000.0;
int c = 110;//long c=110;
//std::cout << std::fixed;
std::cout << std::setbase(16) << a << "\t" << c << std::endl;
//运行后a,c的值变为六进制
std::cout << a << "\t" << c << std::endl;
std::cout << "---------------------------------1" << std::endl;
std::cout << std::setbase(10) << a << "\t" << c << std::endl;
//再将a,c转为十进制
std::cout << "---------------------------------2" << std::endl;
std::cout << std::setprecision(5) << a << "\t" << c << std::endl;
//保留五位数字,对int、long类型无效果
std::cout << std::setprecision(10) << a << "\t" << b << std::endl;
//保留十位数字,10>8,不自动往后补零
std::cout << std::setprecision(10) << std::showpoint << a << "\t" << b << std::endl;
//加上showpoint会自动补零
std::cout << "---------------------------------3" << std::endl;
std::cout << std::fixed;
std::cout << std::setprecision(5) << a1 << "\t" << b1 << std::endl;
//保留小数点后五位数字;添加std::cout << std::fixed;,能够自动补零
std::cout << "---------------------------------4" << std::endl;
std::cout << std::setprecision(4) << std::showpoint << a1 << "\t" << b1 << std::endl;
std::cout << std::setprecision(0) << std::showpoint << a << "\t" << b << std::endl;
}
输出结果