std::moneyp...ecimal_point(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 NAME 🌸

std::moneypunct::decimal_point, do_decimal_point β€” the decimal-point besties for money I/O, straight from the C++ Standard Libary manual (yes, the manual name is spelled β€œLibary” in the header, not me πŸ˜­πŸ’…).


✨ Synopsis ✨

Defined in header <locale> β€” here’s the exact shape of it, bestie:

Defined in header <locale>
public:                                 (1)
CharT decimal_point() const;
protected:                              (2)
virtual CharT do_decimal_point() const;
  1. (1) β€” public member function, and it calls the member function do_decimal_point of the most derived class. Slay.
  2. (2) β€” returns the character to use as the decimal point separator in monetary I/O if the format uses fractions (that is, if do_frac_digits() is greater than zero). For typical U.S. locales, it is the character '.' (or L'.'). 🫢

πŸ’– Return value πŸ’–

The object of type CharT holding the decimal point character. Periodt. ✨


πŸŽ€ Example πŸŽ€

// Run this code

#include <iomanip>
#include <iostream>
#include <locale>

void show_dpt(const char* locname)
{
    std::locale loc(locname);
    std::cout.imbue(loc);
    std::cout << locname << " decimal point is '"
              << std::use_facet<std::moneypunct<char>>(loc).decimal_point()
              << "' for example: " << std::showbase << std::put_money(123);
    if (std::use_facet<std::moneypunct<char>>(loc).frac_digits() == 0)
        std::cout << " (does not use frac digits)";

    std::cout << '\n';
}

int main()
{
    show_dpt("en_US.utf8");
    show_dpt("ja_JP.utf8");
    show_dpt("sv_SE.utf8");
    show_dpt("de_DE.utf8");
}

πŸ’… Output πŸ’…

en_US.utf8 decimal point is '.' for example: $1.23
ja_JP.utf8 decimal point is '.' for example: οΏ₯123 (does not use frac digits)
sv_SE.utf8 decimal point is ',' for example: 1,23 kr
de_DE.utf8 decimal point is ',' for example: 1,23 €

πŸ¦‹ See also πŸ¦‹

  • do_frac_digits β€” provides the number of digits to display after the decimal point. It’s a [virtual] (virtual protected member function). πŸ‘‘

That’s the whole vibe, bestie. Source/version: http://cppreference.com, 2024.06.10, page: std::moneyp...ecimal_point(3). Now go format some money and slay. πŸ’Έβœ¨

πŸ“¦ where this page comes from