#include <iostream>
#include <iomanip>
int main()
{
double a = 115.965;
std::cout << a << std::endl;
std::cout << std::setprecision(3 + 2) << a << std::endl;
double b = 248.515;
std::cout << b << std::endl;
std::cout << std::setprecision(3 + 2) << b << std::endl;
std::cin.get();
return 0;
}
115.965
115.97
248.51
248.51
Dlaczego takie odpowiedzi pokazuje? W ogóle tego nie rozumiem. Skoro jest "piątka" to powinno zaokrąglić w górę, a tu że tego nawet nie robi to jeszcze od razu ucina. Swoją drogą jak napiszę samo:
#include <iostream>
#include <iomanip>
int main()
{
double b = 248.515;
std::cout << b << std::endl;
std::cout << std::setprecision(3 + 2) << b << std::endl;
std::cin.get();
return 0;
}
To odpalając program mam:
248.515 - przed zaokrągleniem
248.51 - po zaokrągleniu