阿拉伯数字转中文
程序员文章站
2022-03-26 12:05:06
...
好久没写了,最近刚好用到一个财务上的金额由数字转换为中文的内容,写了个函数实现,记录下:
class MoneyConstConfig { /** * 金额数字中文映射 */ public static $NUM_CH_MAP = array( 0 => '零', 1 => '壹', 2 => '贰', 3 => '叁', 4 => '肆', 5 => '伍', 6 => '陆', 7 => '柒', 8 => '捌', 9 => '玖', ); /** * 金额层次中文映射 */ public static $FINANCE_UNIT_MAP = array( 0 => '分', 1 => '角', 2 => '圆', 3 => '拾', 4 => '佰', 5 => '仟', 6 => '万', 7 => '拾', 8 => '佰', 9 => '仟', 10 => '亿', 11 => '拾', ); }
'', // 仟万 * '8' => '', // 佰万 * '7' => '', // 拾万 * '6' => '', // 万 * '5' => '', // 仟 * '4' => '', // 佰 * '3' => '', // 拾 * '2' => '', // 圆 * '1' => '', // 角 * '0' => '', // 分 * ); */ public static function ticketFinanceChDesc($sourceNum) [67/1580] { $sourceNum = number_format($sourceNum, 2, '.', ''); // 保证金额是精确到分 $numArr = self::parseNumToArr($sourceNum); if (false !== ($key = array_search('.', $numArr))) { unset($numArr[$key]); } $rnumArr = array_reverse($numArr); $data = array(); $i = 0; foreach ($rnumArr as $num) { $data[$i++] = $num; } if ($i $num) { if ($num != 0) { if ($exists0 === true) { $chStr .= '零'; $exists0 = false; } $chStr .= MoneyConstConfig::$NUM_CH_MAP[$num] . MoneyConstConfig::$FINANCE_UNIT_MAP[$key]; } else { $exists0 = true; } if ($key == $yuan) { $chStr = rtrim($chStr, self::YUAN_POINT); $chStr .= self::YUAN_POINT; } elseif ($key == $wan) { $chStr = rtrim($chStr, self::WAN_POINT); $chStr .= self::WAN_POINT; } elseif ($key == $yi) { $chStr = rtrim($chStr, self::YI_POINT); $chStr .= self::YI_POINT; } } return $chStr; } }
以上就介绍了阿拉伯数字转中文,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。