目标c -在IOS上打印漂亮的大数

objective c - Printing nice large numbers c++ on IOS

本文关键字:漂亮 打印 IOS 目标      更新时间:2023-10-16

我正在寻找一种很好的方法来打印大数,使它们更易于阅读

即6000000

应该

6.000.000

6,000,000,取决于语言环境

更新

我已经尝试了以下我的代码(它在IOS上)

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

localeSet总是nil

和我总是得到"LCOALE AFTER: C"

在std 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;
...