php对数字进行万、亿单位的转化
作者:一颗糊涂淡 时间:2023-06-24 08:34:32
php对数字进行万。亿的转化
/**
* 格式化数字
*/
public function float_number($number){
$length = strlen($number); //数字长度
if($length > 8){ //亿单位
$str = substr_replace(strstr($number,substr($number,-7),' '),'.',-1,0)."亿";
}elseif($length >4){ //万单位
//截取前俩为
$str = substr_replace(strstr($number,substr($number,-3),' '),'.',-1,0)."万";
}else{
return $number;
}
return $str;
}
知识点扩充:
PHP 数字转为大写金额(面向对象版)
本人在网上找了很久都没个完整能用的,于是只好自己写个(有效位数整数部分至千万亿,小数部分至小数点后四位)
$time_start=getmicrotime();
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
/// CLASS BEGIN //
class Num2cny
{
/** 大写数字*/
private $cny_num = array('零','壹','贰','参','肆','伍','陆','柒','捌','玖');
/** 整数部分的单位*/
private $cny_int_unit = array('圆','拾','佰','仟','万','拾','佰','仟','亿','拾','佰','仟','万','拾','佰','仟');
/** 小数部分的单位*/
private $cny_dec_unit = array('角','分','厘','毫');
/** 大于1吗*/
private $greater_than_1 = FALSE;
/**
* 转为大写金额。
* @access public
* @param string
* @return string
*/
public function conversion($str) {
if(empty($str))
{
return 'Please input a numeric value!';
}
if( ! is_numeric($str))
{
return 'It is not a numeric value!';
}
$str = str_replace(',','',trim($str));// 过滤掉左右空格和逗号
$str = ltrim($str,'0');
$_integerStr = '';// 整数部分数字
$_decimalStr = '';// 小数部分数字
来源:https://www.cnblogs.com/zhangcheng001/p/15069605.html
标签:php,单位转化
0
投稿
猜你喜欢
mysql导入导出命令
2011-07-04 11:28:50
ORM框架之Dapper简介和性能测试
2024-05-03 15:30:44
Python字符串的创建和驻留机制详解
2022-07-07 18:49:17
mysql 循环批量插入的实例代码详解
2024-01-16 10:28:23
解决MySQL 5.7中定位DDL被阻塞的问题
2024-01-14 10:20:01
MySQL学习之数据库操作DML详解小白篇
2024-01-14 11:59:48
两个命令把 Vim 打造成 Python IDE的方法
2022-01-20 09:31:31
go micro微服务proto开发安装及使用规则
2024-03-19 14:40:13
Python实现批量检测HTTP服务的状态
2023-02-21 12:50:55
Python运行的17个时新手常见错误小结
2023-05-20 00:13:17
一些实用性较高的js方法
2024-04-29 13:37:40
15个开发者必须知道的chrome技巧
2022-08-27 20:24:33
JavaScript快速实现一个颜色选择器
2024-04-28 09:38:09
Python3.8安装Pygame教程步骤详解
2022-05-11 15:26:15
探究数组排序提升Python程序的循环的运行效率的原因
2021-07-16 21:35:06
在Python中使用matplotlib模块绘制数据图的示例
2023-08-01 01:39:45
Python 面向对象编程详解
2023-06-25 05:24:23
Pytorch 的 LSTM 模型的示例教程
2021-08-01 22:28:41
python爬虫实例之获取动漫截图
2023-08-17 22:13:57
Python Django框架介绍之模板标签及模板的继承
2021-11-05 01:36:56