PHP关于数据的舍入关键字归类

  下面是关于数字转化的几种方法:

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://www.cnblogs.com/blueskyc/archive/2008/06/25/1229891.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值