Search code examples
c++visual-c++

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.

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.

The output shows a strange value.


Solution

  • int p = 3.1415926536;
    

    should be

    double p = 3.1415926536;