Namespaces
Variants
Views
Actions

std::numpunct::decimal_point, std::numpunct::do_decimal_point

From cppreference.com
< cpp‎ | locale‎ | numpunct
Revision as of 06:15, 23 April 2013 by P12 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <locale>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td >
public:
char_type decimal_point() const;
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
protected:
char_type virtual do_decimal_point() const;
</td>

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

1) Public member function, calls the member function do_decimal_point of the most derived class.

2) Returns the character to be used as the decimal separator between integer and fractional parts.

Return value

The object of type char_type to use as the thousands separator. The standard specializations of std::numpunct return ’.’ and L’.’.

Example

#include <iostream>
#include <locale>
 
struct slash : std::numpunct<char> {
    char do_decimal_point()   const { return '/'; }  // separate with slash
};
 
int main()
{
    std::cout.precision(10);
    std::cout << "default locale: " << 1234.5678 << '\n';
    std::cout.imbue(std::locale(std::cout.getloc(), new slash));
    std::cout << "locale with modified numpunct: " << 1234.5678 << '\n';
}

Output:

default locale: 1234.5678
locale with modified numpunct: 1234/5678