moneypunct::grouping


public member function
string grouping() const;

Return grouping of digits

Returns a sequence of integer values indicating the number of digits in each group.

The sequence is returned as a string (basic_string<char>) where each char element shall be interpreted as an integer value indicating the number of digits in each group. Grouping is considered from right to left, with the first character in the string being used for the rightmost group, and the last character used for any group farther away than the length of the string.

For example, "\03" indicates groups of three digits each, while "\02\03" would indicate that the rightmost group has two digits and all the remaining ones have three digits each.

A negative value in the string or a value equal to CHAR_MAX indicates that the number of digits in the group is unlimited.

En empty string indicates no grouping.

During its operation, the version of this function in the generic template simply calls the virtual protected member do_grouping, which is the member function in charge of performing the actions described above.

Parameters

none

Return value

A string object containing a sequence of digit grouping values.
Notice that this is an object of type basic_string<char> no matter what character type is used as template parameter.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[h3]Example[/h3]
[code]
// moneypunct example
#include <iostream>
#include <locale>
using namespace std;

// overload inserter to print patterns:
ostream& operator<< (ostream& os, moneypunct<char>::pattern p)
{
  for (int i=0; i<4; i++)
    switch (p.field[i]) {
      case moneypunct<char>::space: cout << "space "; break;
      case moneypunct<char>::symbol: cout << "symbol "; break;
      case moneypunct<char>::sign: cout << "sign "; break;
      case moneypunct<char>::value: cout << "value "; break;
    }
  return os;
}

int main ()
{
  locale mylocale;
  const moneypunct<char>& mp = use_facet<moneypunct<char> >(mylocale);

  cout << "moneypunct in locale \"" << mylocale.name() << "\":\n";

  cout << "decimal_point: " << mp.decimal_point() << endl;
  cout << "thousands_sep: " << mp.thousands_sep() << endl;
  cout << "grouping: " << mp.grouping() << endl;
  cout << "curr_symbol: " << mp.curr_symbol() << endl;
  cout << "positive_sign: " << mp.positive_sign() << endl;
  cout << "negative_sign: " << mp.negative_sign() << endl;
  cout << "frac_digits: " << mp.frac_digits() << endl;
  cout << "pos_format: " << mp.pos_format() << endl;
  cout << "neg_format: " << mp.neg_format() << endl;
  
  return 0;
} 


Possible output:

moneypunct in locale "C":
decimal_point:
thousands_sep:
grouping:
curr_symbol:
positive_sign:
negative_sign: -
frac_digits: 0
pos_format: symbol sign value
neg_format: symbol sign value


See also