PHP converts the number 1.1 billion to a kanji representation, such as 150 turns 150
Directly on the instance
Written to hundreds of billions.
/**
* @author ja Ode
* Replace the number 1.1 billion with Chinese characters, such as:123-> 123
* @param [num] $num [number]
* @return [string] [string]
*/
function Numtoword ($num)
{
$chiNum = Array (' 0 ', ' one ', ' two ', ' three ', ' four ', ' V ', ' VI ', ' VII ', ' VIII ', ' IX ');
$chiUni = Array (' ', ' ten ', ' hundred ', ' thousand ', ' million ', ' billion ', ' ten ', ' hundred ', ' thousand ');
$CHISTR = ";
$num _str = (string) $num;
$count = strlen ($num _str);
$last _flag = true; Whether the previous is 0
$zero _flag = true; Whether the first one
$temp _num = null; Provisional numbers
$CHISTR = ";//Stitching result
if ($count = = 2) {//two digits
$temp _num = $num _str[0];
$CHISTR = $temp _num = = 1? $chiUni [1]: $chiNum [$temp _num]. $chiUni [1];
$temp _num = $num _str[1];
$chiStr. = $temp _num = = 0? ": $chiNum [$temp _num];
}else if ($count > 2) {
$index = 0;
for ($i = $count-1; $i >= 0; $i-) {
$temp _num = $num _str[$i];
if ($temp _num = = 0) {
if (! $zero _flag &&! $last _flag) {
$CHISTR = $chiNum [$temp _num]. $CHISTR;
$last _flag = true;
}
}else{
$CHISTR = $chiNum [$temp _num]. $chiUni [$index%9]. $chiStr;
$zero _flag = false;
$last _flag = false;
}
$index + +;
}
}else{
$CHISTR = $chiNum [$num _str[0]];
}
return $chiStr;
}
$num = 150;
echo Numtoword ($num);