yaml-cpp icon indicating copy to clipboard operation
yaml-cpp copied to clipboard

YAML Floating Point Precision in Output Files

Open holdsworth opened this issue 4 years ago • 4 comments
trafficstars

When saving a file with new API you cannot set explicitly the number of digits after the . thus when having a double of the form 1.0 it is saved as 1, which causes issues later on if you're deducing parameter type based on input, this badly hurts the config file (especially when you re-save it)

The fix would be to modify the last else in inner_encode function (line 102 in node/convert.h file) from stream << ... to stream << std::setprecision(12) << std::fixed << rhs;

Note that you can expose the set precision to be externally modified, would you like me to send a PR?

holdsworth avatar Jul 28 '21 08:07 holdsworth

Sure

On Wed, Jul 28, 2021 at 3:03 AM holdsworth @.***> wrote:

When saving a file with new API you cannot set explicitly the number of digits after the . thus when having a double of the form 1.0 it is saved as 1, which causes issues later on if you're deducing parameter type based on input, this badly hurts the config file (especially when you re-save it)

The fix would be to modify the last else in inner_encode function (line 102 in node/convert.h file) from stream << ... to stream << std::setprecision(12) << std::fixed << rhs;

Note that you can expose the set precision to be externally modified, would you like me to send a PR?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jbeder/yaml-cpp/issues/1016, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAICUBWXIE7ZK2AOLRH3WKLTZ62WRANCNFSM5BD2CIQA .

jbeder avatar Jul 28 '21 23:07 jbeder