位置: 编程技术 - 正文
推荐整理分享PHP字符串函数number_format()的用法(php中字符串函数),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:php字符串函数大全,php 字符串 数组,php 字符串函数,php 字符串函数,php字符串定义,php 字符串函数,php字符串型数据的定义方式,php 字符串函数,内容如对您有帮助,希望把文章链接给更多的朋友!
(PHP 4, PHP 5)
number_format — 以千位分隔符方式格式化一个数字
说明 string number_format ( float $number [, int $decimals = 0 ] ) string number_format ( float $number , int $decimals = 0 , string $dec_point = . , string $thousands_sep = , )本函数可以接受1个、2个或者4个参数(注意:不能是3个):
如果只提供第一个参数,number的小数部分会被去掉 并且每个千位分隔符都是英文小写逗号","
如果提供两个参数,number将保留小数点后的位数到你设定的值,其余同楼上
如果提供了四个参数,number 将保留decimals个长度的小数部分, 小数点被替换为dec_point,千位分隔符替换为thousands_sep
参数number
你要格式化的数字
decimals要保留的小数位数
dec_point指定小数点显示的字符
thousands_sep指定千位分隔符显示的字符
返回值格式化以后的 number.
更新日志版本 说明 5.4.0 This function now supports multiple bytes in dec_point and thousands_sep. Only the first byte of each separator was used in older versions.
范例
Example #1 number_format() Example
For instance, French notation usually use two decimals, comma (,) as decimal separator, and space ( ) as thousand separator. This is achieved with this line :
<?php$number=.;//englishnotation(default)$english_format_number=number_format($number);//1,//Frenchnotation$nombre_format_francais=number_format($number,2,',','');//,$number=.;//englishnotationwithoutthousandsseparator$english_format_number=number_format($number,2,'.','');//.?> 参见money_format() - Formats a number as a currency string sprintf() - Return a formatted string printf() - 输出格式化字符串 sscanf() - 根据指定格式解析输入的字符
PHP字符串函数quoted_printable_encode()的用法 quoted_printable_encode(PHP5=5.3.0)quoted_printable_encode将8-bit字符串转换成quoted-printable字符串说明stringquoted_printable_encode(string$str)返回quoted-printable格式的字符,该
PHP字符串函数parse_str()的用法 parse_str(PHP4,PHP5)parse_str将字符串解析成多个变量说明voidparse_str(string$str[,array&$arr])如果str是URL传递入的查询字符串(querystring),则将它解析为变量并设
PHP字符串函数quotemeta()的用法 quotemeta(PHP4,PHP5)quotemetaQuotemetacharacters说明stringquotemeta(string$str)Returnsaversionofstrwithabackslashcharacter()beforeeverycharacterthatisamongthese:.+*?[^]($)参数strTheinputstring.
标签: php中字符串函数
本文链接地址:https://www.jiuchutong.com/biancheng/278845.html 转载请保留说明!友情链接: 武汉网站建设