如何阻止大型浮点数以指数形式输出.(科学计数法?)

dar*_*rko 4 c++

我有一个计算人口增长的计划.它似乎有效,但是当人口超过100万时,输出的十进制数增加到10的幂.(这被称为科学符号吗?指数形式?我忘了.)

无论如何输出数据作为完整数字?这是输出的代码,我将不得不转换它.

#include "header.h"

void output (float currentPopulation, float years, float birthRate, float deathRate)

{     
     cout <<  "the populaion in " << years << " years will be: " << estimatedPopulation (currentPopulation, years, birthRate, deathRate) << endl;
}   
Run Code Online (Sandbox Code Playgroud)

新代码:

#include "header.h"

    void output (float currentPopulation, float years, float birthRate, float deathRate)

    {     
         cout <<  "the populaion in " << years << " years will be: " << fixed << setprecision(0) << estimatedPopulation (currentPopulation, years, birthRate, deathRate) << endl;
    } 
Run Code Online (Sandbox Code Playgroud)

ice*_*ime 7

std::fixed与之配合使用的操纵器std::setprecision应该可以帮助你(记住#include <iomanip>).