Search code examples
c++boostlocalizationformattinglocale

boost locale format percentage


I have a problem with boost::locale::format outputting as a percentage. According to the documentation (http://www.boost.org/doc/libs/1_48_0/libs/locale/doc/html/localized_text_formatting.html):

Numbers and number manipulators

Here are the manipulators for number formatting:

as::number -- format number according to local specifications, it takes into account 
as::percent -- format number as "percent" format. For example:

        cout << as::percent << 0.25 <<endl;

Would create an output that may look like this:

    25%

However, the following outputs "0.25":

#include <string>
#include <iostream>
#include <boost/system/system_error.hpp>
#include <boost/locale.hpp>


int main(int argc, char** argv)
{
    std::cout << boost::locale::as::percent << 0.25 <<std::endl;
}

I have tried imbuing std::cout with an EN-US locale through std::locale() as well as a locale generated by boost::locale::generator to no avail.

It seems like I'm missing some obvious problem; could anyone hint at it please?


Solution

  • Boost.Locale uses 4 backends (ICU, posix, winapi, std), but only ICU backend has percentage feature, that means the library you're using is not compiled with ICU library.

    You can see which feature can be used with which backend in Supported Features table.