Boost C++ Libraries: Ticket #9545: program_options description printout bug https://svn.boost.org/trac10/ticket/9545 <p> When setting the default value of a float option to 0.05, the help description that is printed by the program states that the default value is 0.0500000007. For double, it states "0.050000000000000003". The value of the variable within the program is correct, i.e. 0.05. </p> <p> I'm compiling with: </p> <p> $ g++ --version g++ (GCC) 4.8.3 20131226 (prerelease) </p> <p> Here is a test program that reproduces the problem when run with the option "--help": </p> <pre class="wiki">#include "boost/program_options.hpp" int main(int argc, char ** argv) { float dt; boost::program_options::variables_map vm; boost::program_options::options_description desc("Description"); desc.add_options() ("help", "Print help message") ("dt", boost::program_options::value&lt;float&gt;(&amp;dt)-&gt;default_value(0.05), "Time step") ; boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); boost::program_options::notify(vm); if(vm.count("help")) desc.print(std::cout); std::cout &lt;&lt; "dt = " &lt;&lt; dt &lt;&lt; "\n"; return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9545 Trac 1.4.3 Vladimir Prus Tue, 07 Jan 2014 16:24:16 GMT <link>https://svn.boost.org/trac10/ticket/9545#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9545#comment:1</guid> <description> <p> I think the printed value is the correct one. 0.05 likely cannot be represented by IEEE floating point types. If you want to show "0.05" to user, please use the second argument to 'default_value' to specify the presentation in help output. </p> </description> <category>Ticket</category> </item> <item> <author>torquil@…</author> <pubDate>Tue, 07 Jan 2014 18:44:42 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9545#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9545#comment:2</guid> <description> <p> Thanks, that seems very likely. So it is the intentional lower default precision of std::cout that makes it print 0.05, which is an approximation to the actual variable value. And it would in fact add those zeroes and the final nonzero digit if its precision was increased sufficiently using setprecision(). </p> <p> But I guess std::cout uses a lower default precision intentionally, and perhaps the same should at least be considered for the program_options printout. </p> <p> So it seems that this is just an esthetic problem, and can even be changed using the second argument as you stated, so I will simply let it print the value that it does at the moment. The extra digits don't bother me much. </p> </description> <category>Ticket</category> </item> </channel> </rss>