问题:
I want to write a method that will take an integer and return a std::string
of that integer formatted with commas. 我想编写一个方法,它将接受一个整数并返回一个用逗号格式化的整数的std::string
。
Example declaration: 示例声明:
std::string FormatWithCommas(long value);
Example usage: 示例用法:
std::string result = FormatWithCommas(7800);
std::string result2 = FormatWithCommas(5100100);
std::string result3 = FormatWithCommas(201234567890);
// result = "7,800"
// result2 = "5,100,100"
// result3 = "201,234,567,890"
What is the C++ way of formatting a number as a string
with commas? 用逗号将数字格式化为string
的 C++ 方法是什么?
(Bonus would be to handle double
s as well.) (额外的好处是也可以处理double
。)
解决方案: 参考:
https://stackoom.com/en/question/UX2A
来源:https://my.oschina.net/u/4428122/blog/5403587
码神部落- 版权声明
1、本主题所有言论和图片纯属会员个人意见,与码神部落 立场无关。
2、本站所有主题由该帖子作者发表,该帖子作者对牛谈情 与码神部落 享有帖子相关版权。
3、码神部落 管理员和版主有权不事先通知发贴者而删除本文。
4、其他单位或个人使用、转载或引用本文时必须同时征得该帖子作者对牛谈情 和码神部落 的同意。
5、帖子作者须承担一切因本文发表而直接或间接导致的民事或刑事法律责任。
6、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责。
7、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意。