我想使用mpdf将数字转换成单词。
46a7f55 Final Production working build
在我的td标签中
$sum=1000;
答案 0 :(得分:0)
我使用了类似的功能,该功能改编自先前的堆栈溢出answer。它解决了一些涉及十进制货币值的极端情况。它可以取任意数量,并转换成印度货币格式(拉赫斯,克洛斯,卢比,佩斯等)。在功能下方找到:
/**
* Converting Currency Numbers to words currency indian format
*/
function convert_to_currency_indian_format($amount) {
if ($amount == 0) {
return "Zero Rupees Only";
}
//$number = 190908100.25;
$number = round($amount, 2);
$no = floor($number);
$point = round($number - $no, 2) * 100;
$hundred = null;
$digits_1 = strlen($no);
$i = 0;
$str = array();
$words = array('0' => '', '1' => 'one', '2' => 'two',
'3' => 'three', '4' => 'four', '5' => 'five', '6' => 'six',
'7' => 'seven', '8' => 'eight', '9' => 'nine',
'10' => 'ten', '11' => 'eleven', '12' => 'twelve',
'13' => 'thirteen', '14' => 'fourteen',
'15' => 'fifteen', '16' => 'sixteen', '17' => 'seventeen',
'18' => 'eighteen', '19' => 'nineteen', '20' => 'twenty',
'30' => 'thirty', '40' => 'forty', '50' => 'fifty',
'60' => 'sixty', '70' => 'seventy',
'80' => 'eighty', '90' => 'ninety');
$digits = array('', 'hundred', 'thousand', 'lakh', 'crore');
while ($i < $digits_1) {
$divider = ($i == 2) ? 10 : 100;
$number = floor($no % $divider);
$no = floor($no / $divider);
$i += ($divider == 10) ? 1 : 2;
if ($number) {
$plural = (($counter = count($str)) && $number > 9) ? 's' : null;
$hundred = ($counter == 1 && $str[0]) ? 'and ' : null;
$str [] = ($number < 21) ? $words[$number] .
" " . $digits[$counter] . $plural . " " . $hundred :
$words[floor($number / 10) * 10]
. " " . $words[$number % 10] . " "
. $digits[$counter] . $plural . " " . $hundred;
} else
$str[] = null;
}
$str = array_reverse($str);
$result = implode('', $str);
$points = ($point) ?
$words[10 * (int) ($point / 10)] . " " .
$words[$point = $point % 10] : '';
if (!empty($points)) {
return ucwords($result) . "Rupees " . ucwords($points) . " Paise Only";
} else {
return ucwords($result) . "Rupees Only ";
}
}