博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP关于数据的舍入归类:round、ceil、floor、number_format
阅读量:7173 次
发布时间:2019-06-29

本文共 1115 字,大约阅读时间需要 3 分钟。

  hot3.png

下面是关于数字转化的几种方法:
round -- 对浮点数进行四舍五入
例子:
<?php
echo round(3.4);         // 3
echo round(3.6);         // 4
echo round(3.60);      // 4
echo round(1.955832);  // 1.96
echo round(1241757, -3); // 1242000
echo round(5.0552);    // 5.06
?>
ceil -- 进一法取整
例子:
<?php
echo ceil(4.3);    // 5
echo ceil(9.999);  // 10
?>
floor -- 舍去法取整,跟ceil刚刚相反
例子:
<?php
echo floor(4.3);   // 4
echo floor(9.999); // 9
?>
number_format -- 格式化数字为千分位

<?php

$number = 1234;

// english notation (default)

$english_format_number = number_format($number);
echo "First:".$english_format_number."<br />";

// French notation

$nombre_format_francais = number_format($number, 2, ',', ' ');
echo "Second:".$nombre_format_francais."<br />";

// French notation

$number = 1234.564;
$nombre_format_francais = number_format($number, 2, ',', ' ');
echo "Third:".$nombre_format_francais."<br />";
$number = 1234.5678;

// english notation without thousands seperator

$english_format_number = number_format($number, 2, '.', '');
echo "Forth:".$english_format_number."<br />";

?>

显示结果最终如下:
First:1,234
Second:1234,00
Third:1234,56
Forth:1234.57

转载于:https://my.oschina.net/junn/blog/95829

你可能感兴趣的文章
android: BaseAdapter和ListView简单运用(08)
查看>>
自带内存上的读写(openFileOutput和openFileInput)
查看>>
服务器搭建:3.2、openresty图片压缩之 lua调用GraphicsMagick
查看>>
bash 脚本编程 变量、变量类型 (笔记)
查看>>
win7 管理员权限
查看>>
docker下redis集群搭建
查看>>
composer出现proc_open,fileinfo问题
查看>>
无ROWID优化(The WITHOUT ROWID Optimization)
查看>>
Android第七课 探索Activity的生命周期
查看>>
求排列
查看>>
Cisco-CCNP之OSPF链路状态路由协议(三)
查看>>
CentOS 7 系列(一)系统服务 systemd
查看>>
Hive 数据倾斜总结
查看>>
mysql查询结果处理
查看>>
扫描识别控件Dynamic Web TWAIN v12.3.1发布,更新服务证书丨附下载
查看>>
VintaSoft PDF插件VintaSoftPDF.NET Plug-in更新至v5.6,新增多页查看模式
查看>>
windows环境中不重启电脑杀死占用某个端口的进程
查看>>
“90+68”的完美转变
查看>>
Kubernetes上的负载均衡详解
查看>>
centos7格式化大于2T的硬盘
查看>>