Answers for "how to print numbers with only 2 digits after decimal point in c++"

C++
0

how to print numbers with only 2 digits after decimal point in c++

#include <cstdio>
#include <iostream>

int main() {
    double total;
    cin>>total;
    printf("%.2f\n", total); 
    //one can use the C function to print the decimal points
}
Posted by: Guest on August-29-2021
0

how to print numbers with only 2 digits after decimal point in c++

#include <iostream>
#include <iomanip>
#include <iostream>
​
int main()
{
	double d = 122.345;
	cout << fixed << setprecision(2) << d;
  	//the setprecision can vary as per required
}
Posted by: Guest on August-29-2021

Code answers related to "how to print numbers with only 2 digits after decimal point in c++"

Browse Popular Code Answers by Language