On Wed, 8 Oct 2025 at 10:09, Matt Borland <matt@mattborland.com> wrote:
On Wednesday, October 8th, 2025 at 9:53 AM, Richard Hodges via Boost < boost@lists.boost.org> wrote:
- What is your evaluation of the design?
There seems to be no way to construct a boost.decimal from a string representing a decimal number.
Is that correct, or have I missed it?
Without a constructor or conversion mechanism from string, when using decimal to store numbers received off the wire one would either have to round trip through (lossy) strtod or write a conversion function, which is tiresome.
The best way to do this (and how current users are) is via the <charconv> functions[1]. There are also literals if you prefer to go that route [2].
This is a terrible user experience, and the opposite of "make simple things simple". Why not just have a constructor that constructs the decimal from a string? I noted the literals, but these are irrelevant as the pain will come when accepting text inputs and building decimals from them. As things stand I think boost.multiprecision remains a better solution because of this one feature. I appreciate that John's intent is to implement the standard verbatim, but this has frankly never been a good idea.
Almost all financial systems (an obvious candidate for a class such as this) spend most of their time converting decimals to strings and strings to decimals. I see that serialisation is covered by fmt integration, but what about parsing?
R
Does {fmt} even support parsing beyond parsing of the context? I am not aware of that if it does.
I did not mean to imply that {fmt} includes parsing. Merely that serialisation is covered by {fmt}, but that parsing is not covered (other than by the from_chars complication).
Matt
[1] https://develop.decimal.cpp.al/decimal/charconv.html [2] https://develop.decimal.cpp.al/decimal/literals.html