Matt Borland wrote:
Either of those would be fine for me:
decimal64_t dec("3.142"); // or auto dec = stod64("3.142");
That basically already exists with strtod functions:
decimal64_t dec = strtod64("3.142", nullptr);
This also handles locales like you would expect, which is useful if you have for example German formatting of currency.
And not useful at all if you don't. :-) Most of the time, the input values are in the C locale. <cstdio> functions being locale-aware has caused many programmer-years of trouble. E.g. your example may produce 3142 because the current locale is Italian. This is very rarely accurately described as "handles locales as you would expect". In the typical case where the input comes over the wire, it's never a good idea to assume that the sender has magically consulted your current locale and tailored the output to it. TL;DR being locale-aware by default causes many more problems than it solves (if it has ever solved any), and <cstdio> is basically useless if your locale isn't guaranteed "C".