无法打印pi的更多小数 [英] can't print more decimal of pi

查看:172
本文介绍了无法打印pi的更多小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的程序中使用long double类型打印出更多的pi数字。

I have tried to use long double type in my program to print out more digits of pi. But it only shows 5 digits decimal.

以下是我的代码。

int main(int argc, char** argv) {

    long double pi_18 = acos(static_cast<long double>(-1));
    cout << "pi to 18:" << pi_18 << endl;

    return 0;
}

这是我的输出:

pi to 18: 3.14159

我修复了这个问题?

推荐答案

如下:

#include <iomanip>
#include <iostream>

std::cout << std::setw(15) << pi_18 << std::endl;

宽度修改器仅影响下一个格式化操作,因此如果要格式化多个数字,在每一个之前重复它。请查看格式说明符的完整文档

The width modifier only affects the next formatting operation, so if you want to format multiple numbers, you have to repeat it before every one. Check out the full documentation of format specifiers.

这篇关于无法打印pi的更多小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆