Answers for "how to round float to 2 decimal places in c"

C++
1

rounding decimal number in C

#include <stdio.h>
#include <math.h>
 int main()
{
       float i=5.4, j=5.6;
       printf("round of  %f is  %fn", i, round(i));
       printf("round of  %f is  %fn", j, round(j));
       return 0;
}
Posted by: Guest on July-30-2021
2

round number at 2 decimal places

Math.round(num * 100) / 100
Posted by: Guest on March-17-2021
2

how to make floats output with 2 decimals c++

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	float x=10.3445f;
	
	cout<<fixed<<setprecision(5)<<x<<endl;
	cout<<fixed<<setprecision(2)<<x<<endl;
	cout<<fixed<<setprecision(3)<<x<<endl;
	cout<<fixed<<setprecision(0)<<x<<endl;
	
	return 0;
}
Posted by: Guest on April-18-2020

Code answers related to "how to round float to 2 decimal places in c"

Browse Popular Code Answers by Language