How to cout a float number with n decimal places [duplicate]

You need std::fixed and std::setprecision:

 std::cout << std::fixed << std::setprecision(3) << a;

These require following header:

#include <iomanip>

Leave a Comment