Rumah  >  Artikel  >  pembangunan bahagian belakang  >  php使用number_format函数截取小数的方法分析,number_format小数_PHP教程

php使用number_format函数截取小数的方法分析,number_format小数_PHP教程

WBOY
WBOYasal
2016-07-12 08:50:49971semak imbas

php使用number_format函数截取小数的方法分析,number_format小数

本文实例讲述了php使用number_format函数截取小数的方法。分享给大家供大家参考,具体如下:

大家知道用php的number_format()函数可以将数字按千分组. 但是它会使数字四舍五入, 那有没有办法能让它直接舍弃保留位后面的小数而不进行四舍五入呢?各位别急,且听我细细道来,如果你想保留两位小数,可以把你的数字-0.005

例如:

123456.6588

你想要得结果是:

123,456.65

你可以这样:

$num=123456.6588;
echo number_format($num-0.005,2, ".", ",");

如果你只想保留整数可以

$num=123456.6588;
number_format($num-0.5);

问题搞定!

补充:小编在这里推荐一款本站的php格式化美化的排版工具帮助大家在以后的PHP程序设计中进行代码排版:

php代码在线格式化美化工具:

http://tools.jb51.net/code/phpformat

另外,由于php属于C语言风格,因此下面这款工具同样可以实现php代码的格式化:

C语言风格/HTML/CSS/json代码格式化美化工具:
http://tools.jb51.net/code/ccode_html_css_json

更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP数学运算技巧总结》、《php操作office文档技巧总结(包括word,excel,access,ppt)》、《PHP数组(Array)操作技巧大全》、《php排序算法总结》、《PHP常用遍历算法与技巧总结》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《php正则表达式用法总结》、《PHP运算与运算符用法总结》、《php字符串(string)用法总结》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1133064.htmlTechArticlephp使用number_format函数截取小数的方法分析,number_format小数 本文实例讲述了php使用number_format函数截取小数的方法。分享给大家供大家参考,...
Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn