2075 / C++ / Форматування виводу
#include <iomanip> double a = 1.123; cout << setprecision(1) << a << endl; cout << fixed << setprecision(1) << a << endl; cout << setprecision(2) << a << endl; cout << fixed << setprecision(2) << a << endl; cout << setprecision(3) << a << endl; cout << fixed << setprecision(3) << a << endl; double b = 1.1; cout << "-------------" << endl; cout << setprecision(3) << b << endl; cout << fixed << setprecision(3) << b << endl;
1
1.1
1.12
1.12
1.123
1.123
————-
1.100
1.100
1.1
1.12
1.12
1.123
1.123
————-
1.100
1.100
Додавати нуль, якщо цифра <10
setw(2) << setfill('0') << second ;