当前位置:网站首页>学习在php中将特大数字转成带有千/万/亿为单位的字符串
学习在php中将特大数字转成带有千/万/亿为单位的字符串
2022-08-04 09:19:00 【徊忆羽菲】
学习在php中将特大数字转成带有千/万/亿为单位的字符串
第一种方法:ifelse
/** * @param int $num 要转换的阿拉伯数字 * @return string 转换成的字符串 */
function convert($num)
{
if ($num >= 100000000) {
$num = round($num / 100000000, 1) . '亿+';
} else if ($num >= 10000000) {
$num = round($num / 10000000, 1) . '万+';
} else if ($num >= 10000) {
$num = round($num / 10000, 1) . '万+';
} else if ($num >= 1000) {
$num = round($num / 1000, 1) . '千+';
}
return $num;
}
第二种方法:switch
function convert_new($num)
{
switch ($num) {
case ($num > 100000000):
$num = round($num / 100000000, 1) . '亿+';
break;
case ($num > 10000000):
$num = round($num / 10000000, 1) . '千万+';
break;
case ($num > 10000):
$num = round($num / 10000, 1) . '万+';
break;
case ($num > 1000):
$num = round($num / 1000, 1) . '千+';
break;
}
return $num;
}
echo '1234=' . convert(1234);
echo "<br>";
echo '1234=' . convert_new(1234);
echo "<br>";
结果展示
1234=1.2千+
1234=1.2千+
12345=1.2万+
12345=1.2万+
123456=12.3万+
123456=12.3万+
1234567=123.5万+
1234567=123.5万+
12345678=1.2万+
12345678=1.2千万+
123456789=1.2亿+
123456789=1.2亿+
1234567890=12.3亿+
1234567890=12.3亿+
边栏推荐
- 三层交换机配置MSTP协议详解【华为eNSP实验】
- Detailed explanation of telnet remote login aaa mode [Huawei eNSP]
- 用OpenGL绘制winXP版扫雷的笑脸表情
- LeetCode简单题之最好的扑克手牌
- 软件工程国考总结——判断题
- telnet远程登录aaa模式详解【华为eNSP】
- async - await
- Explanation of spark operator
- [Punctuality Atom STM32 Serial] Chapter 2 STM32 Introduction Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1
- async - await
猜你喜欢

TiFlash 源码阅读(五) DeltaTree 存储引擎设计及实现分析 - Part 2

leetcode二叉树系列(一)

JSP基本语法

【正点原子STM32连载】第二章 STM32简介 摘自【正点原子】MiniPro STM32H750 开发指南_V1.1

layout manager

Anton Paar Anton Paar Density Meter Hydrometer Repair DMA35 Performance Parameters
![Detailed explanation of NAT/NAPT address translation (internal and external network communication) technology [Huawei eNSP]](/img/82/f76e87689599f3501a13f83c0fa970.png)
Detailed explanation of NAT/NAPT address translation (internal and external network communication) technology [Huawei eNSP]

思想茶叶蛋 (Jul 31,2022)| 元宇宙(Metaverse)下了一枚什么样的蛋
![Detailed explanation of switch link aggregation [Huawei eNSP]](/img/c2/f9797fe8b17a418466b60cc3dc50a1.png)
Detailed explanation of switch link aggregation [Huawei eNSP]
![[Punctuality Atom STM32 Serial] Chapter 2 STM32 Introduction Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1](/img/11/a97c9874a1c4b510e7ed9ec330a737.png)
[Punctuality Atom STM32 Serial] Chapter 2 STM32 Introduction Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1
随机推荐
华为od项目
架构设计杂谈
LVGL's multi-language conversion tool -- a good assistant for font settings
Unity3D data encryption
罗克韦尔AB PLC RSLogix5000中定时器指令使用方法介绍
ps如何换背景颜色,自学ps软件photoshop2022,3种不同的方式笔记记录
Oracle怎么获取当前库或者同一台服务器上某几个库的数据总行数?
命里有时终须有--记与TiDB的一次次擦肩而过
Layer 3 Switch/Router OSPF Configuration Details [Huawei eNSP Experiment]
抬升市场投资情绪,若羽臣是否还需“自身硬”?
并发编程之生产者和消费者问题
leetcode二叉树系列(二)
ZbxTable 2.0 重磅发布!6大主要优化功能!
2022-08-02 分析RK817 输出32k clock PMIC_32KOUT_WIFI给WiFi模块 clock 注册devm_clk_hw_register
B站回应HR称“核心用户都是Loser”、求职者是“白嫖党”:已被劝退
yuv420sp转jpg
sync-diff-inspector 使用实践
2022年化工自动化控制仪表考试模拟100题及模拟考试
How Oracle for current library or certain library data on the same server number?
【C补充】指向指针或函数的指针