<?php
/**
* Renminbi amount converted to uppercase Chinese
* @param float $number The amount of money to be converted.
* @return string The converted uppercase Chinese string.
*/
function number_to_chinese($number) {
$fraction = ['Horn', 'Points'];
$digit = ['Zero', 'One', 'II', 'Three', 'Rampant', 'Woo', 'Land', 'Seven', 'Eight', 'Nine'];
$unit = [['Yuan', 'Wan', 'Billions'], ['', 'Pick up', 'Bai', 'Thousand']];
$ret = '';
if ($number == 0) {
return 'Zero dollars';
}
$numbers = explode('.', $number);
if (count($numbers) > 1) {
$integer_part = $numbers[0];
$fraction_part = $numbers[1];
} else {
$integer_part = $number;
$fraction_part = '';
}
// Convert the integer part
for ($i = 0; $i < strlen($integer_part); $i++) {
$p = strlen($integer_part) - $i - 1;
$temp = $integer_part[$i];
if ($temp == '0') {
if ($p == 0 || (0 < $p && $p % 4 == 0)) {
$ret .= $digit[$temp];
}
} else {
$ret .= $digit[$temp] . $unit[0][floor($p / 4)] . ($p % 4 < 3 ? $unit[1][$p % 4] : '');
}
}
// Add decimal part
if ($fraction_part != '') {
$ret .= 'Point';
for ($i = 0; $i < strlen($fraction_part); $i++) {
$ret .= $digit[$fraction_part[$i]];
}
}
return $ret;
}
// Example of use
$number = 12345.67;
echo number_to_chinese($number); // Output: Twelve thousand, three hundred and thirty-five dollars and seventeen cents.