千分位显示整数
来源:互联网 发布:淘宝客 余杭区法院 编辑:程序博客网 时间:2024/04/28 21:14
转自:把长的数字用逗号隔开显示(千分位)
/*copy from http://m.blog.csdn.net/article/details?id=8681982make a little modify*/std::string int2str_withcommas(int64_t number){ std::string result_str; //'digit_num' specifies the num of digits //'comma_num' specifies the num of commas //'str_len' specifies the length of the string //'head\tail' specifies the flag of the algorithm unsigned int digit_num = 0, comma_num = 0, str_len = 0, head = 0, tail = 0; int64_t fabsNumber = fabs(number); int64_t tmp = fabsNumber; //calculate the num of digits do { digit_num++; tmp /= 10; } while (tmp > 0); //calculate the num of commas comma_num = (digit_num-1) / 3; //calculate the length of the string if (number < 0) { str_len = digit_num + 1 + comma_num; result_str.resize(str_len); result_str[0] = '-'; tail = 2; } else { str_len = digit_num + comma_num; result_str.resize(str_len); tail = 1; } //treat per three letters as a block head = str_len;// result_str[str_len] = '\0'; //main algorithm while (str_len >= tail/* && fabsNumber > 0*/) { if ((head - str_len) == 3) { result_str[str_len - 1] = ','; str_len--; head -= 4; } result_str[str_len - 1] = fabsNumber % 10 + '0'; fabsNumber /= 10; str_len--; } return result_str;}
阅读全文
0 0
- 千分位显示整数
- 千分位显示
- 转换千分位显示
- 数字用千分位显示
- 设置千分位格式显示
- java实现数字千分位的显示
- C#中金额千分位显示
- C#中金额千分位显示
- GP或oracle数值千分位显示
- java让数字显示千分位
- yii2 数字以千分位格式显示
- 千分位
- 千分位
- JSP整数转化为千分位的使用
- DBGrid 中的显示-数字用千分位来显示
- 用正则轻松搞定千分位显示问题
- js数字千分位显示的两个关键函数
- 用正则轻松搞定千分位显示问题
- C语言打印正六边形
- Redis开发及集群
- iOS检测应用更新-iVersion
- YAML 语言教程
- JAVA ueditor + OSS 上传图片整合
- 千分位显示整数
- Spring Bean装配--常用的注入方式和自动装配的配置和实现
- 优化 SQL SELECT 语句性能的技巧
- bzoj4883 4886 图论新高度!!!!!
- python自学笔记1
- (设计模式)装饰者模式-java
- 腾讯云服务器 重启后出现(无法连接,或者502 bad gate)
- vmware:网络架构(持续更新)
- hitTest:withEvent:方法流程