简体   繁体   中英

How do I set the precision of a floating variable in C++?

我已经尝试过setprecision()方法,但 IDE 显示“未在范围内声明”错误。

In order to allow for std::precision() you should look at the example below:

#include <iomanip>
#include <iostream>

int main() { 
    std::cout << std::setprecision(5) << 3.44444444444 << std::endl;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM