#include#include int main() { double myNumber = 3.14159; std::cout << std::setprecision(3) << myNumber << std::endl; return 0; }
#includeIn this example, the `std::fixed` function is used to ensure that the floating-point number `myNumber` is displayed with a fixed number of decimal places. The `std::setprecision(2)` function is used to set the precision to two decimal places. The output will be `1.23`. Both of these examples use the standard library in C++ and do not require any additional packages.#include int main() { double myNumber = 1.234567; std::cout << std::fixed << std::setprecision(2) << myNumber << std::endl; return 0; }