Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
611 views
in Technique[技术] by (71.8m points)

double - How to make C++ cout not use scientific notation

double x = 1500;
for(int k = 0; k<10 ; k++){
    double t = 0;
    for(int i=0; i<12; i++){
        t += x * 0.0675;
        x += x * 0.0675;
    }
    cout<<"Bas ana: "<<x<<"Son faiz: "<<t<<"Son ana: "<<x+t<<endl;      
}

this the output

Bas ana: 3284.78 Son faiz: 1784.78 Son ana: 5069.55

Bas ana: 7193.17 Son faiz: 3908.4 Son ana: 11101.6

Bas ana: 15752 Son faiz: 8558.8 Son ana: 24310.8

Bas ana: 34494.5 Son faiz: 18742.5 Son ana: 53237

Bas ana: 75537.8 Son faiz: 41043.3 Son ana: 116581

Bas ana: 165417 Son faiz: 89878.7 Son ana: 255295

Bas ana: 362238 Son faiz: 196821 Son ana: 559059

Bas ana: 793246 Son faiz: 431009 Son ana: 1.22426e+006

Bas ana: 1.73709e+006 Son faiz: 943845 Son ana: 2.68094e+006

Bas ana: 3.80397e+006 Son faiz: 2.06688e+006 Son ana: 5.87085e+006

I want numbers to be shown with exact numbers not scientific numbers. How can I do this?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use std::fixed stream manipulator:

cout<<fixed<<"Bas ana: "<<x<<"Son faiz: "<<t<<"Son ana: "<<x+t<<endl;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...