PHP 浮点数 转化 整数方法对比 ceil,floor,round,intval,number_format
ceil,floor,round,intval,number_format - 执行1000W此效率对比
Header("Content-Type:text/html;charset=utf-8");
ini_set('memory_limit','-1');
set_time_limit(0);
$count = 10000000;
$num = 73.1221;
$q = time();
for($i=0; $i<$count; $i++){
number_format($num, 0);
}
echo 'number_format耗时:'.( time()-$q ).'<br/>';
$w = time();
for($i=0; $i<$count; $i++){
floor($num);
}
echo 'floor耗时:'.( time()-$w ).'<br/>';
$e = time();
for($i=0; $i<$count; $i++){
ceil($num);
}
echo 'ceil耗时:'.( time()-$e ).'<br/>';
$r = time();
for($i=0; $i<$count; $i++){
intval($num);
}
echo 'intval耗时:'.( time()-$r ).'<br/>';
$t = time();
for($i=0; $i<$count; $i++){
round($num);
}
echo 'round耗时:'.( time()-$t ).'<br/>';
//输出:
number_format耗时:11
floor耗时:3
ceil耗时:3
intval耗时:2
round耗时:5
ceil,floor,intval 相差无几
PHP 浮点数 转化 整数方法对比 ceil,floor,round,intval,number_format的更多相关文章
- PHP取整函数之ceil,floor,round,intval的区别
我们经常用到的PHP取整函数,主要是:ceil,floor,round,intval. ceil -- 进一法取整 说明 float ceil ( float value ) 返回不小于 value ...
- PHP取整函数:ceil,floor,round,intval的区别详细解析
floor -- 舍去法取整说明float floor ( float value ) 返回不大于 value 的下一个整数,将 value 的小数部分舍去取整.floor() 返回的类型仍然是 fl ...
- Objective-C浮点数转化整数(向上取整、向下取整)
Objective-C拓展了C,自然很多用法是和C一致的.比如浮点数转化成整数,就有以下四种情况. 1.简单粗暴,直接转化 float f = 1.5; int a; a = (int)f; NSLo ...
- 关于取整函数ceil(),floor(),round()函数得应用
ceil()返回向上取整最接近的整数. double ceil(double); floor()返回向下取整最接近的整数. double floor(double); round()用于对浮点数的四舍 ...
- O-C浮点数转化整数
1.简单粗暴,直接转化 float f = 1.5; int a; a = (int)f; NSLog("a = %d",a); 输出结果是1.(int)是强制类型转化,丢弃浮点数 ...
- javascript中Math ceil(),floor(),round()三个函数的对比
Math.ceil()执行的是向上舍入 Math.floor()执行向下舍入 Math.round()执行标准舍入 一下是一些补充: ceil():将小数部分一律向整数部分进位. 如: Math.ce ...
- php取整函数floor(),round(),intval(),ceil()
ceil -- 进一法取整说明float ceil ( float value )返回不小于 value 的下一个整数,value 如果有小数部分则进一位.ceil() 返回的类型仍然是 float, ...
- Math对象(min()-max()-ceil()-floor()-round()和abs())
1.Math.min() 功能:求一组数的最小值,返回值:Number 如果里面有非数字则返回NaN 2.Math.max() 功能:求一组数的最大值,返回值:Number 3.Math.ceil() ...
- php函数 ceil floor round和 intval
1.ceil 如果有小数部分 则进一位 < ?php echo ceil(4.3); echo ceil(9.999); ?> 2.floor 舍小取整 < ? php echo f ...
随机推荐
- iOS隐藏导航条1px的底部横线
第二种方法:1)声明UIImageView变量,存储底部横线 @implementation MyViewController { UIImageView *navBarHairlineImageVi ...
- Knowing how all your components work together: distributed tracing with Zipkin
转自: http://aredko.blogspot.com/2014/02/knowing-how-all-your-components-work.html In today's post we ...
- Codeforces768C Jon Snow and his Favourite Number 2017-02-21 22:24 130人阅读 评论(0) 收藏
C. Jon Snow and his Favourite Number time limit per test 4 seconds memory limit per test 256 megabyt ...
- 阿里杨传辉的访问节选(oceanbase)
皮皮(Q4): OceanBase第一个应用是收藏夹.最近,听说支付宝交易也用到了OceanBase.能否结合阿里的应用谈谈OceanBase的优势. 杨传辉(A4):相比传统的关系数据库,谈及Oce ...
- 18-11-03 Scrum Meeting 6
1. 会议照片 2. 工作记录 完成的工作 配置页面 实现中译英选择题和英译中选择题的查询接口 整理文档 完成一个网站的图片爬取 计划的工作 完善配置页面功能 补充另一个网站的图片爬取 代码整理测试 ...
- Websocket出现的错误
前端使用sockjs,后台使用spring的websocket框架 结果在一个网络较慢的地方,发现tomcat报错信息: Oct 28, 2015 10:10:43 AM org.apache.cat ...
- ViewPage实现无限轮播画廊效果
1. 效果图 2. 布局文件 主要使用的 android:clipChildren的意思:是否限制子View在其范围内.再父布局和viewpager中设置该属性 ,要显示三个界面 ,还要设置marg ...
- Jenkins的多个任务并串联参数传递
Jenkins的多个任务并串联参数传递 Parameterized Trigger Plugin插件可以使多个job连接的时候可以传递一些job相关的参数信息. 1.Parameterized Tri ...
- 4-C#格式处理
本篇博客对应视频讲解 前言 前几篇文章及对应视频是带大家快速体验了一下C#,了解编程语言最基础的内容及面向对象的概念. 接下来我会进一步演示和说明C#还能做些什么. 实际上,C#就一门语言来讲,除去面 ...
- Ubuntu add-apt-repository: command not found
在Ubuntu下,时不时会有这个错误的. add-apt-repository: command not found 这个是缺少程序,安装一下就可以了.只是不知道安装的名字. 按以下命令走一趟就可以的 ...