Turn off scientific notation on float

后端 未结 2 446
星月不相逢
星月不相逢 2020-12-04 01:29

I\'m trying to display number in standard notation

for example:

float f = 1230000.76

turns out to be,

1.23e+006
         


        
2条回答
  •  孤城傲影
    2020-12-04 02:05

    Use -

    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    

    before printing out the floating point numbers.

    More information can be found here.

    You can also set output precision with the following statement -

    cout.precision(2);
    

    or simply with -

    printf("%.2f", myfloat);
    

提交回复
热议问题