Maximum Width of a Printed Double in C++ -


I was wondering, how many times would the number of characters be printed in double by using fprintf? My guess is wrong.

Thanks in advance.

Who knows the standard does not say how many points of accuracy a double Provide other than to say (3.9.1.8) "Provides at least the exact form of float," so that you actually how many characters you have to sprintf An arbitrary value will be required even if you know how much your implementation provides, yet there is a question of exponential formatting and so on.

But here's a big question why would you care for the cat? I'm guessing because you are trying to write something like this:

  double d = ...; Int MAGIC_NUMBER = ...; Four buffer [MAGIC_NUMBER]; Sprintoff (buffer, "% f", d);  

There is a bad way to do it, okay because you do not know that the bigger MAGIC_NUMBER should be. You can choose something that should be bigger than 14 or 128k, but then the number you choose is arbitrary, not based on anything but estimates it will be quite big. The number is like MAGIC_NUMBER , not surprisingly, is called. Stay away from them they cry one day.

Instead, there are many ways to do this string formatting without taking care of the buffer size, precision points, so that you can meet with the business, the stream of programming is one:

  #include & lt; Sstream & gt; Double d = ...; Stringstream ss; SS & lt; & Lt; D; String s = ss.str (); Cout & lt; & Lt; S;  

... The second is:

  #include & lt; Boost \ format \ format.hpp & gt; Double d = ...; String S = (boost :: format ("% 1%")% d) .str (); Cout & lt; & Lt; S;  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -