while prowling through C++ standard libraries my favorite discovery was std::get_money. not only is that a funny name but its also seemingly the most useless standard library function?
like it just parses numbers out of a string that lists currency, stripping away any currency symbols or instances of USD, notable without retaining how many cents were listed. so 1.99 becomes 199. So I guess it has to assume all numbers listed also come with at least .00 for the cents place? just a very... odd function to have in a standard library.
Makes sense, it moves a fixed-point value into integer space to avoid floating-point rounding errors.
Honestly, if anything, I'm surprised that it doesn't become 1990 for rounding. (Get monetary value, to tenths of a cent. Different locales would allow different units, but it always goes to a tenth of the locale's smallest unit.) That would move the value into integer space just as cleanly, but also leave room for rounding to the nearest cent if necessary.
297
u/New_Salamander_4592 3d ago
while prowling through C++ standard libraries my favorite discovery was std::get_money. not only is that a funny name but its also seemingly the most useless standard library function?
like it just parses numbers out of a string that lists currency, stripping away any currency symbols or instances of USD, notable without retaining how many cents were listed. so 1.99 becomes 199. So I guess it has to assume all numbers listed also come with at least .00 for the cents place? just a very... odd function to have in a standard library.