固定小数精度 [英] Fixed Decimal Precision

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

问题描述

我当前正在使用

std::cout.precision(5);

设置输出的小数精度.但是,我宁愿有我的输出总是输出5个小数位(现在它不会显示0).我该如何更改代码以反映这一点?

to set the decimal precision of my outputs. However, I would rather have my output ALWAYS output 5 decimal places (right now it won't show 0's). How would I change my code to reflect this?

推荐答案

您正在寻找 std :: fixed std :: setprecision .

#include <iomanip>
#include <iostream>
double f =1.1;
std::cout << std::fixed;
std::cout << std::setprecision(5) << f << std::endl;

stdout

1.10000

这篇关于固定小数精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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