C++ cout 小数位输出控制


叫“魔法配方”吗?

#include 

int main()
{
    using namespace std;

    double price = 75;

    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(3);

    cout << "价格是 $" << price << endl;

    getchar();
    return 0;
}

输出:

价格是 $75.000