php amount value amount of capital converted to Chinese

/**
* Convert amount value amount of Chinese capital
* @Param $ amount float amount (points)
* @Param $ type int full complement type, 0: up to the corner integer; 1: to fill the whole element
* @Return mixed Chinese capital amount
*/
function convertAmountToCn($amount, $type = 1)
{
if ($amount == 0) {
return "zero dollars whole";
}
 
if (strlen($amount) > 12) {
return "does not support trillion and higher amounts";
}
 
// array of predefined Chinese conversion
$ Digital = array ( 'zero', 'One', 'II', 'three', 'store', 'Wu', 'LU', 'qi', 'split', 'ND');
// array of predefined unit conversions
$ Position = array ( 'thousand', 'Bai', 'pick up', 'one hundred million', 'thousand', 'Bai', 'pick up', 'Wan', 'thousand', 'Bai', 'pick up', ' yuan');
 
// Value String split into an array amount
$amountArr = explode('.', $amount);
// split bit integer values ​​into an array of strings
$integerArr = str_split($amountArr[0], 1);
 
// uppercase characters will replace the integer part
$ Result = 'RMB';
$integerArrLength = count($integerArr);
$positionLength = count($position);
for ($i=0; $i<$integerArrLength; $i++) {
$result = $result . $digital[$integerArr[$i]]. $position[$positionLength - $integerArrLength + $i];
}
 
// If you have to convert decimal places
if ($type == 1) {
// decimal places split into an array of strings
$decimalArr = str_split($amountArr[1], 1);
// replaces the fractional part of uppercase characters
$result = $result . $digital[$decimalArr[0]] . '角' . $digital[$decimalArr[1]] . '分';
} else {
$result = $result . '整';
}
 
return $result;
}

Guess you like

Origin www.cnblogs.com/ssx314/p/11368628.html