我使用php函数将数字转换为单词。但是当数字的值返回超过lacs时,它返回了。
例如,当数值为113034时,其返回“十一万三千三十四”。但欲望的输出将是“一个一万三千三百四十一”。有谁知道怎么做?
function numberToWords ($number)
{
$words = array ('zero',
'one',
'two',
'three',
'four',
'five',
'six',
'seven',
'eight',
'nine',
'ten',
'eleven',
'twelve',
'thirteen',
'fourteen',
'fifteen',
'sixteen',
'seventeen',
'eighteen',
'nineteen',
'twenty',
30=> 'thirty',
40 => 'fourty',
50 => 'fifty',
60 => 'sixty',
70 => 'seventy',
80 => 'eighty',
90 => 'ninety',
100 => 'hundred',
1000=> 'thousand');
if (is_numeric ($number))
{
$number = (int) round($number);
if ($number < 0)
{
$number = -$number;
$number_in_words = 'minus ';
}
if ($number > 1000)
{
$number_in_words = $number_in_words . numberToWords(floor($number/1000)) . " " . $words[1000];
$hundreds = $number % 1000;
$tens = $hundreds % 100;
if ($hundreds > 100)
{
$number_in_words = $number_in_words . ", " . numberToWords ($hundreds);
}
elseif ($tens)
{
$number_in_words = $number_in_words . " and " . numberToWords ($tens);
}
}
elseif ($number > 100)
{
$number_in_words = $number_in_words . numberToWords(floor ($number / 100)) . " " . $words[100];
$tens = $number % 100;
if ($tens)
{
$number_in_words = $number_in_words . " and " . numberToWords ($tens);
}
}
elseif ($number > 20)
{
$number_in_words = $number_in_words . " " . $words[10 * floor ($number/10)];
$units = $number % 10;
if ($units)
{
$number_in_words = $number_in_words . numberToWords ($units);
}
}
else
{
$number_in_words = $number_in_words . " " . $words[$number];
}
return $number_in_words;
}
return false;
}
echo numberToWords(113034);