时间:2021-07-01 10:21:17 帮助过:8人阅读
header("Content-type: text/html; charset=utf-8");
function removeAfterZero($str) {
$s = $str;
$r = '';
for ($i = strlen($s)-1; $i > 0; $i--) {
if ($s[$i] == 0) {
$s = substr($s, 0, $i);
$r = $s;
} else {
break;
}
}
return $r;
}
$num = 1000100;
if (strlen(strlen($num) < 5))
echo $num;
else if (strlen($num) >= 5 && strlen($num) < 6) {
if (removeAfterZero(substr($num, 1, strlen($num)-1)) == 0)
echo substr($num, 0, 1) . "万";
else
echo substr($num, 0, 1) . '.' . removeAfterZero(substr($num, 1, strlen($num)-1)) . "万";
}else if (strlen($num) >= 6 && strlen($num) < 7) {
if (removeAfterZero(substr($num, 2, strlen($num)-2)) == 0)
echo substr($num, 0, 2) . "万";
else
echo substr($num, 0, 2) . '.' . removeAfterZero(substr($num, 2, strlen($num)-2)) . "万";
}else if (strlen($num) >= 7 && strlen($num) < 8) {
if (removeAfterZero(substr($num, 3, strlen($num)-3)) == 0)
echo substr($num, 0, 3) . "万";
else
echo substr($num, 0, 3) . '.' . removeAfterZero(substr($num, 3, strlen($num)-3)) . "万";
}
$num = 100000;
echo $num < 10000 ? $num : $num/10000 . '万';