Opened 13 years ago

Closed 13 years ago

#2994 closed Feature Requests (fixed)

default value output precision

Reported by: anonymous Owned by: Vladimir Prus
Milestone: Boost 1.39.0 Component: program_options
Version: Boost 1.38.0 Severity: Not Applicable
Keywords: Cc: s.ochsenknecht@…

Description

If I make an option like this: ("maxlength", po::value<double>(&MaxLength)->default_value(.1), "Maximum edge length to keep.")

The help message looks like this: --maxlength arg (=0.10000000000000001) Maximum edge length to keep.

It probably should default to fewer decimal points.

Attachments (1)

ticket2994.patch (893 bytes ) - added by s.ochsenknecht@… 13 years ago.
test case

Download all attachments as: .zip

Change History (5)

by s.ochsenknecht@…, 13 years ago

Attachment: ticket2994.patch added

test case

comment:1 by s.ochsenknecht@…, 13 years ago

I'm afraid that a certain, hard coded, output precision wouldn't satisfy all users. But there as an overloaded version of default_value() which can be used to define the string representation of the default value:

("maxlength", po::value<double>(&MaxLength?)->default_value(.1, "0.1"), "Maximum edge length to keep.") 

This string is then used for the help output. I would recommend to use this approach.

I attached a test case to show the usage of this functionality. Maybe documentation needs to be updated.

Please comment.

comment:2 by s.ochsenknecht@…, 13 years ago

Cc: s.ochsenknecht@… added

comment:3 by s.ochsenknecht@…, 13 years ago

BTW: For all other values (were no string representation of the default value is defined) boost::lexical_cast<>() is used.

comment:4 by Sascha Ochsenknecht, 13 years ago

Resolution: fixed
Status: newclosed

(In [57817]) added test case, Fixes #2994

Note: See TracTickets for help on using tickets.