double i = 2.5373737373737....
Is there anyway to get rid of decimals after 2 digits decimals so it can be 2.57? (without displaying it by using setprecision)
double i = 2.5373737373737....
Is there anyway to get rid of decimals after 2 digits decimals so it can be 2.57? (without displaying it by using setprecision)
setprecision(int) function in iomanip can help to print with required precision.
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
double i =2.537373737;
std::cout << setprecision(3) << i << '\n';
}