Double to scientific Noton conversion tht Ey int Es0y ll for tep 3

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

c++: How do I convert a double to scientific notation, like 45765.98696 to 4.576598696E4 or -0.0069607895 to -6.9607895E-3? 

tat Ey int Es0y l/for sep 3
Double
conversion to scientific Notaton
doab te dy
int nuber of digsts;
I Count how many diavts there are in d. If there is
Wy one do gt which is zero, print "oE O,"
2) If there is only one NaNt, whichh is non zeto,
now thinking that I could
set E=0y when I declare it, so that regard lers
can just print
zero might jut
print (d+"E O "). I am
of d Geing
zero
of non-2ero
(d+"E"+0), but then agaln, adding
blank space.
be
adding
If thete is more than one digit
Ef uo decimat anyuebete , photint ft //its a double, there
3) If decimal is placed anywhere but in betureen
first non zero Ngst and its preceding digst, move decmal
there. If decimal goer in right dire ction, E-- , if
In left
4) Print (d+ "E"+E),
must bé a deeimal
Ett.
Transcribed Image Text:tat Ey int Es0y l/for sep 3 Double conversion to scientific Notaton doab te dy int nuber of digsts; I Count how many diavts there are in d. If there is Wy one do gt which is zero, print "oE O," 2) If there is only one NaNt, whichh is non zeto, now thinking that I could set E=0y when I declare it, so that regard lers can just print zero might jut print (d+"E O "). I am of d Geing zero of non-2ero (d+"E"+0), but then agaln, adding blank space. be adding If thete is more than one digit Ef uo decimat anyuebete , photint ft //its a double, there 3) If decimal is placed anywhere but in betureen first non zero Ngst and its preceding digst, move decmal there. If decimal goer in right dire ction, E-- , if In left 4) Print (d+ "E"+E), must bé a deeimal Ett.
Expert Solution
Step 1 rule to conversion

 I convert a double to scientific notation

Add std::fixed to stream i.e.

// Set Fixed -Point Notation
streamObj2 << std::fixed;


It will force the c++ to convert double using fixed-point notation instead of scientific one. For example,

// Create an output string stream
std::c++ streamObj2;
 
// Set Fixed -Point Notation
streamObj2 << std::fixed;
 
//Add double to stream
streamObj2 << num;
// Get string from output string stream
std::string strObj2 = streamObj2.str();
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY