round double to n decimal places c++

#include <iostream>
#include <iomanip>
#include <cmath>

int main() {
    double number;
    int decimalPlaces;

    // Input the double number and the desired decimal places
    std::cout << "Enter a double number: ";
    std::cin >> number;
    std::cout << "Enter the number of decimal places: ";
    std::cin >> decimalPlaces;

    // Calculate the multiplier to shift the decimal places
    double multiplier = std::pow(10.0, decimalPlaces);

    // Round the number to the specified decimal places
    double roundedNumber = std::round(number * multiplier) / multiplier;

    // Set the precision for output
    std::cout << std::fixed << std::setprecision(decimalPlaces);

    // Display the rounded number
    std::cout << "Rounded number to " << decimalPlaces << " decimal places: " << roundedNumber << std::endl;

    return 0;
}