[英]How to format the output of cout using float values?
I found one ways to show my float value like decimal, but when I use in my code, didn´t show as I want it. 我找到了一种显示浮点值(如十进制)的方法,但是当我在代码中使用时,并没有按我的期望显示。
int p = 3.1415926536;
cout << setprecision(3) << p <<"\t";
I´m using c++ in visual studio 2010. 我在Visual Studio 2010中使用c ++。
I need to know this because when I multiply a matrix it shows wrong values, but debbugin I see there is no error in my code. 我需要知道这一点,因为当我将一个矩阵相乘时,它会显示错误的值,但是debbugin我看到我的代码中没有错误。
The output shows a strange value. 输出显示一个奇怪的值。
int p = 3.1315926536
应该
double p = 3.1415926536;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.