Square :: getArea()太难了

时间:2018-12-09 15:27:59

标签: c++

我想使该区域的输出达到小数点后第二位。 例如,输出:width = 2 height = 33 area = 66.00 但是这段代码的输出是width = 2 height = 33 area = 66

double Square::getArea(){
    return width * height;
}
void Square::print(){
    cout << " : width=" << (int)width << " height=" << (int)height << " area=" << Square::getArea();
}

1 个答案:

答案 0 :(得分:1)

使用以下语句肯定可以解决您的问题std::setprecision(number of digits)