php格式化数字输出number_format
<?php
$num = 4999.944444;
$formattedNum = number_format($num).PHP_EOL;
echo $formattedNum;
$formattedNum = number_format($num, 2);
echo $formattedNum;
5,000
4,999.94
<?php
$num = 4999.945444;
$formattedNum = number_format($num).PHP_EOL;
echo $formattedNum;
$formattedNum = number_format($num, 2);
echo $formattedNum;
5,000
4,999.95
由此可见,number_format是4舍5入的策略。
<?php
$num = 4999.944444;
$formattedNum = number_format($num).PHP_EOL;
echo $formattedNum;
$formattedNum = number_format($num, 1);
echo $formattedNum;
5,000
4,999.9
<?php
$num = 4999.954444;
$formattedNum = number_format($num).PHP_EOL;
echo $formattedNum;
$formattedNum = number_format($num, 1);
echo $formattedNum;
5,000
5,000.0
它会将留的小数位后面一位作为四舍五入的标准。
php格式化数字输出number_format的更多相关文章
- PHP字符串的处理(二)-字符串的格式化
1.字符串大小写的转换 strtoupper():将字符串全部转换为大写字母 strtolower():将字符串全部转换为小写字母 ucfirst():将字符串中的首字母转换为大写,其余字符不变 uc ...
- 【Swift】iOS开发历险记(一)
前言 边开发边学习,边攒经验,汇总一下记录到这里 声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cnblogs.com 农民伯伯: http://over140.cnblog ...
- PHP笔记(PHP初级篇)
学习完HTML和CSS后,终于要开始学习PHP啦!前面的铺垫只为后路的畅顺! PHP环境搭建: 企业中常用到的环境是:Linux+Apache+MySQL+PHP 学习环境是:Windows+Apac ...
- featherview模板引擎
1.判断语法 <?php if(isset($value['fromVR']) && !empty($value['fromVR'])) {?> <s class=& ...
- PHP部分---字符串处理(文中例子不断更新);
字符串处理: 1.去除 ltrim(),rtrim()函数 trim()函数 trim(字符串名)函数:--去掉字符串两边的空格 ltrim(字符串名,“特殊字符”);--去除字符串左边的空格和 ...
- PHP全栈学习笔记3
trim()函数,用于去除字符串首尾空格和特殊字符 返回的是去掉的空格和特殊字符后的字符串 string trim(string str [,string charlist]); str 要操作的字符 ...
- PHP零基础入门
字符函数库: 函数库基础 安装字符串函数库 字符串函数库列表 函数是可以实现特定功能,可以重复执行的代码段. 函数分 内置函数 和 用户函数. 内置函数是指PHP本身提供的各类库函数. 字符串函数库, ...
- 【Swift】iOS开发笔记(一)
前言 边开发边学习,边攒经验,汇总一下记录到这里 声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cnblogs.com 农民伯伯: http://over140.cnblog ...
- php模板引擎之featherview
在纯php文件中不加php结束符是一个好习惯,php结束符仅用于在php与html混写时标示php代码结束. <? ?>是短标签,<?php ?>是长标签,在php的配置文件( ...
随机推荐
- Spring P命名空间 02
P命名空间 装配属性 使用<property> 元素为Bean 的属性装配值和引用并不太复杂.尽管如此,Spring 的命名空间p 提供了另一种Bean 属性的装配方式,该方式不需要配置如 ...
- Java五大框架
2017-6-13 Lifusen 此文章仅代表个人观点,如有问题提出请联系Q:570429601 1.Hibernate (开放源代码的对象关系映射框架) Hibernate是一个开放源代码的对象关 ...
- right spindle supply short to gnd-- compact version
hardware guy found that the R1004 lead to this error, but this error should not be checked, because ...
- flask模板,路由,消息提示,异常处理
1.flask的路由与反向路由 from flask import Flask, request, url_for app = Flask(__name__) @app.route('/') def ...
- protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - unknown delivery tag 2, class-id=60, method-id=80)
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method<channel.c ...
- Angular 父子组件传值
Angular 父子组件传值 @Input @Output @ViewChild 新建一个头部组件 newsheader 在主组件引用 news 组件,在news组件添加 newsheader 组 ...
- The Usage of Lambda and Heap in the C++ STL
The Usage of Lambda and Heap in the C++ STL Heap In c++ STL, the heap had been implemented as the pr ...
- golang BDD testcase framework.
BDD What is Behaviour Driven Development and why should I care? Behaviour Driven Development (BDD) i ...
- 安装搭建Python2.* 和3.* 环境详细步骤
Python是跨平台的,它可以运行在Windows.Mac和各种Linux/Unix系统上. 安装Python 首先进入Python官方网站,将Python下载下来. win7安装python 在官网 ...
- Eclipse查看Servlet源码
Eclipse查看Servlet源码 @(Java) 1.servlet-api 和 javax.servlet-api的区别 在正式查看Servlet源码前,我们首先要分清楚上述两个jar包的区别. ...