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
426 views
in Technique[技术] by (71.8m points)

c++ - Turn off scientific notation on float

I'm trying to display number in standard notation

for example:

float f = 1230000.76

turns out to be,

1.23e+006
See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

there are two things found in iomanip that must be included....first is fixed and the second is setprecision

you need to write:

cout<< fixed;
cout<< setprecision(2)<< f;

fixed disables the scientific notation i.e. 1.23e+006.... and fixed is a sticky manipulator so u need to disable it if u want to revert back to scientific notation...


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

2.1m questions

2.1m answers

60 comments

57.0k users

...