float roundoff(float value, unsigned char prec)
{
float pow_10 = pow(10.0f, (float)prec);
return round(value * pow_10) / pow_10;
}
auto rounded = roundoff(100.123456, 3);
// rounded = 100.123;
value = round( value * 100.0 ) / 100.0; // 2 decimal places
value = round( value * 1000.0 ) / 1000.0; // 3 decimal places
double d = 0.12345;
std::cout.precision(2); // for accuracy to 2 decimal places
std::cout << d << std::endl; // 0.12
double d;
std::cout.precision(3); // for accurancy to 3 decimal places
std::cout << d << std::endl;
float a,b,c,d,sum;
cin>>a>>b>>c>>d; // reading decimal values
sum=(a*b*c*d);
sum=round(sum*100)/100; // here it is for 2 decimal points
if((float)sum < (float) 9.58)
cout<<"YES
";
else
cout<<"NO
";
Code Example |
---|
Cpp :: wine linux |
Cpp :: unordered_map header file c++ |
Cpp :: c++ length of char* |
Cpp :: c++ compare time |
Cpp :: gfgdf |
Cpp :: c++ program to find prime number using function |
Cpp :: C++ switch - case - break |
Cpp :: use ::begin(WiFiClient, url) |
Cpp :: sort stl |
Cpp :: scan line in c++ |
Cpp :: how to put bitset into a string in c++ |
Cpp :: c++ pointer null vs nullptr |
Cpp :: random number generator c++ between 0 and 1 |
Cpp :: resize 2d vector c++ |
Cpp :: opencv c++ image write |
Cpp :: c++ init multidimensional vector |
Cpp :: round up 2 digits float c++ |
Cpp :: why are inline keyword in header c++ |
Cpp :: restting a queue stl |
Cpp :: 1d array |
Cpp :: time_t to int |
Cpp :: sort index c++ |
Cpp :: how to dynamically allocate an array c++ |
Cpp :: stringstream stream number to string |
Cpp :: sort a vector c++ |
Cpp :: rand() c++ |
Cpp :: how to convert ascii to char in cpp |
Cpp :: classes and objects in c++ |
Cpp :: c++ 14 for sublime windoes build system |
Cpp :: how to initialize vector |