Home > Article > Backend Development > How to convert lowercase numbers to uppercase in php
php How to convert lowercase numbers to uppercase: First create a PHP sample file; then use the "private function getChineseNumber($num, $mode = true){...}" method to convert lowercase numbers to uppercase That’s it.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
php realizes the conversion of Arabic numerals to Chinese uppercase
/** * 阿拉伯数字到中文大写转换 * * @param $num * @param bool $mode * @return string */ private function getChineseNumber($num, $mode = true) { $char = array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"); $dw = array("", "拾", "佰", "仟", "", "万", "亿", "兆"); $dec = "点"; $retval = ""; if ($mode) { preg_match_all("/^0*(\d*)\.?(\d*)/", $num, $ar); } else { preg_match_all("/(\d*)\.?(\d*)/", $num, $ar); } if ($ar[2][0] != 00) { $retval = $dec . $this->getChineseNumber($ar[2][0], false); //如果有小数,则用递归处理小数 } if ($ar[1][0] != 00) { $str = strrev($ar[1][0]); for ($i = 0; $i < strlen($str); $i++) { $out[$i] = $char[$str[$i]]; if ($mode) { $out[$i] .= $str[$i] != "0" ? $dw[$i % 4] : ""; if ($str[$i] + $str[($i - 1 >= 0) ? $i - 1 : 0] == 0) { $out[$i] = ""; } if ($i % 4 == 0) { $out[$i] .= $dw[4 + floor($i / 4)]; } } } $retval = join("", array_reverse($out)) . $retval; } return $retval; }
[Recommended learning: "PHP Video Tutorial"]
The above is the detailed content of How to convert lowercase numbers to uppercase in php. For more information, please follow other related articles on the PHP Chinese website!