我正在寻找一种很好的方法来打印大数,使它们更易于阅读
即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;
...