Conversation
|
This looks good for my use-case. |
|
@jbeder this is now ready to go! |
src/fptostring.cpp
Outdated
| * dragonbox only works for floats/doubles not long double | ||
| */ | ||
| std::string FpToString(long double v, size_t precision) { | ||
| std::string FpToString(long double v, bool enforceDot, size_t precision) { |
There was a problem hiding this comment.
I would move this choice higher in the stack, leaving this file untouched.
There was a problem hiding this comment.
This is a great suggestion! I wasn't so happy with only adding dots to fixed point representation, but
when something was printed in scientific notation, it suddenly didn't enforce a dot.
Moving it one step up in the stack fixes this. Also I don't have to touch the unit tests of FpToString :-)
include/yaml-cpp/emitter.h
Outdated
| void SetStreamablePrecision(std::stringstream&) {} | ||
| std::size_t GetFloatPrecision() const; | ||
| std::size_t GetDoublePrecision() const; | ||
| bool GetEnforceFloatDot() const; |
There was a problem hiding this comment.
#namingishard
What about ShowTrailingZero?
There was a problem hiding this comment.
Also great suggestion! Before I was worried that "EnforceFloatDot" could be understood as only being applicable for float but not double or long double. This new name is a clear improvement!
725675e to
9fe3957
Compare
…ating point value This adds a new function Emitter::SetShowTrailingZero(bool). By setting this, floating point values like '0' or '5' will get an extra '.0' attached to force others to parse them as floats. Example: ``` YAML::Emitter emitter; emitter.SetShowTrailingZero(true); emitter << .... ``` Fix jbeder#226 jbeder#412 jbeder#1016 Co-Author: Romain Reignier <romain.reignier@exail.com>
12e5d05 to
2b7375e
Compare
This builds on top of PR #1377 adjusting the functionality.
It adds a new
Emitter::SetEnforceFloatDot(bool b)function, which allows to enforce that values will have a '.0' append if otherwise no '.' would appear.Open questions: Is
SetEnforceFloatDota good name? (open to other names).