Precision of floating point numbers Using these functions floor(), ceil(), trunc(), round() and setprecision() in C++
Precision of floating point numbers Using these functions floor(), ceil(), trunc(), round() and setprecision() in C++
1/2 decimal equal is 0.555555555555555555555 …. An indefinite number of lengths will require the storage of infinite memory, and we usually have 4 or 8 bytes. Floating point numbers thus only store a certain number of important numbers, and the remainder is missing. The accuracy of a floating-point number describes how often significant digits without loss of data it can show. Cout has a standard precision of 6 when extracting floating point, and serializes everything after.
There are few library and methods given below which are used to produce C++ floating point with precision:
The ceil() rounds off of the value given to the nearest integer and more than the amount determined.
Example:
// C++ program to demonstrate working of ceil()
// in C/C++
#include<bits/stdc++.h>
using namespace std;
int main()
{
double a = 2.411, b = 2.500, c = 2.611;
cout << ceil(a) << endl;
cout << ceil(b) << endl;
cout << ceil(c) << endl;
double x1 = -4.411, y1 = -4.500, z1 = -4.611;
cout << ceil(x1) << endl;
cout << ceil(y1) << endl;
cout << ceil(z1) << endl;
return 0;
}
Output:
Floor rounds the specific value down to the nearest integer that is less than the specific amount.