1#include <iostream>
2#include <iomanip>
3
4int main()
5{
6 double d = 122.345;
7
8 std::cout << std::fixed;
9 std::cout << std::setprecision(2);
10 std::cout << d;
11}
1#include <iostream>
2#include <iomanip>
3
4int main()
5{
6 double d = 122.345;
7 std::cout << std::fixed << std::setprecision(2) << d;
8}
9
10//result that get print out: 122.34
1#include <iostream>
2#include <cstdio>
3using namespace std;
4
5int main()
6{
7 // This code helps you to print a number with desired decimal
8 double Number=10.3454;
9 printf("%.3lf",Number);
10
11 return 0;
12}
1std::cout << std::setprecision(2) << std::fixed;
2// where the 2 is how many decimal places you want
3// note you need to <iomanip>