#include <cmath> int main() { float f1 = 3.14159f; float f2 = 3.49321f; std::cout << std::floor(f1 * 10 + 0.5) / 10 << std::endl; std::cout << std::floor(f2 * 10 + 0.5) / 10 << std::endl; std::cout << std::round(f1 * 10) / 10 << std::endl; // C++11 std::cout << std::round(f2 * 10) / 10 << std::endl; // C++11 }
source share