2

我正在寻找一种打印大量数字的好方法,以便它们更具可读性

即6000000

应该

6.000.000

或者

6,000,000 取决于地区

更新

我在我的代码上尝试了以下内容(它在 IOS 上)

char* localeSet = std::setlocale(LC_ALL, "en_US");
cout << "LOCALE AFTER :" << std::locale("").name() << endl;

localeSet 始终为 NILL

我总是得到“LCOALE 之后:C”

4

1 回答 1

0

在标准 C++ 中是这样的:

template < class T >
std::string Format( T number )
{
    std::stringstream ss;
    ss << number;
    const std::string num = ss.str();
    std::string result;
    const size_t size = num.size();
    for ( size_t i = 0; i < size; ++i )
    {
        if ( i % 3 == 0 && i != 0  )
            result = '.' + result;
        result = ( num[ size - 1 - i ] + result );
    }
    return result;
}

...
long x = 1234567;
std::cout << Format( x ) << std::endl;
...
于 2013-01-16T08:16:38.037 回答