1float roundoff(float value, unsigned char prec)
2{
3 float pow_10 = pow(10.0f, (float)prec);
4 return round(value * pow_10) / pow_10;
5}
6
7auto rounded = roundoff(100.123456, 3);
8// rounded = 100.123;
1value = round( value * 100.0 ) / 100.0; // 2 decimal places
2value = round( value * 1000.0 ) / 1000.0; // 3 decimal places
1 float a,b,c,d,sum;
2
3 cin>>a>>b>>c>>d; // reading decimal values
4
5sum=(a*b*c*d);
6
7sum=round(sum*100)/100; // here it is for 2 decimal points
8
9if((float)sum < (float) 9.58)
10 cout<<"YES\n";
11else
12 cout<<"NO\n";
13
1double d = 0.12345;
2std::cout.precision(2); // for accuracy to 2 decimal places
3std::cout << d << std::endl; // 0.12