PHP实现数字格式化,每三位加逗号
<?php function num_format($num){ if(!is_numeric($num)){ return false; } $rvalue=''; $num = explode('.',$num);//把整数和小数分开 $rl = !isset($num['1']) ? '' : $num['1'];//小数部分的值 $j = strlen($num[0]) % 3;//整数有多少位 $sl = substr($num[0], 0, $j);//前面不满三位的数取出来 $sr = substr($num[0], $j);//后面的满三位的数取出来 $i = 0; while($i <= strlen($sr)){ $rvalue = $rvalue.','.substr($sr, $i, 3);//三位三位取出再合并,按逗号隔开 $i = $i + 3; } $rvalue = $sl.$rvalue; $rvalue = substr($rvalue,0,strlen($rvalue)-1);//去掉最后一个逗号 $rvalue = explode(',',$rvalue);//分解成数组 if($rvalue[0]==0){ array_shift($rvalue);//如果第一个元素为0,删除第一个元素 } $rv = $rvalue[0];//前面不满三位的数 for($i = 1; $i < count($rvalue); $i++){ $rv = $rv.','.$rvalue[$i]; } if(!empty($rl)){ $rvalue = $rv.'.'.$rl;//小数不为空,整数和小数合并 }else{ $rvalue = $rv;//小数为空,只有整数 } return $rvalue; }

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools