Am 12.10.25 um 19:27 schrieb Andrzej Krzemienski via Boost:
My numeric values do not have to know the currency they represent, but they need to know the magnitude of the currency's subunit. They can obtain this number during initialization.
Until today, I thought that my use case cannot be handled by a decimal float. But I now hear that this could be a valid use case. I am looking for the following behaviour:
Decimal d{100, -2}; // "1.00" cout << d; // no formatting flags
I expect this to display "1.00": I provided enough information in the initialization that the right cohort should be used so that the exact "1.00" can be recreated during printing.
My question: is the above a use case intended or possible to be handled by Boost.Decimal?
This looks like it intersects with localization rather than common representation. Different countries use different formats for their numbers and currencies. But this only matters at the input/output boundary and should be handled there. This is the same as with e.g. float values: You got to specify somehow how you want it to be displayed. In this case I could also imagine a solution like the following is better suited cout << as_dollar(d); // $1.00 cout << as_yen(d); // 1Y cout << as_dinar(d); // 1.000D Or a strong-type `Dollar` containing a `decimal_t` which has the benefit of not mixing calculations on different currencies TLDR: For specific output you need format flags as with other number types as well which I find reasonable