1、如图中表格数据为例,需要把每个单元格的一串数字每隔3个数字添加一个逗号。
2、把表格全选中。再如图所示,点击这个小按钮。
3、在d出的面板中,点击数字选项,再点击:自定义
4、在类型下面的编辑框内,输入:000,000;再点击确定即可。
用正则,对Java里的正则语法不熟悉,给你个Javascript的:alert('123456'.replace(/(\d)(?=(?:\d{3})+(?!\d))/g, "$1,"))
得到123,456
对于整型数字,是无法直接加逗号的,只能转为字符串形式,再加逗号。
思路为:
1 将数字转为字符串;
2 从尾向头扫描字符串,每三位插入一个逗号。
3 当扫描到字符串开始时, *** 作结束。
示例代码如下:
#include <iostream>#include <string>
#include <sstream>
using namespace std
int main()
{
long l
cin>>l
string str
str << l //转为字符串
size_t len = str.length()
for(int index =(int) len-3 index > 0 index -= 3)
str.insert(index, ",")//插入逗号。
cout<<str<<endl//输出结果。
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)