C++ cout 小数位输出控制

叫“魔法配方”吗?

#include <iostream>

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
posted @ 2022-01-12 16:38  double64  阅读(102)  评论(0)    收藏  举报