@@ -12,14 +12,14 @@ discard block |
||
| 12 | 12 | class Money |
| 13 | 13 | { |
| 14 | 14 | private $money; |
| 15 | - private $uppers = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']; |
|
| 16 | - private $units = ['分', '角']; |
|
| 17 | - private $grees = ['元', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟', '万', '拾', '佰']; |
|
| 15 | + private $uppers = [ '零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖' ]; |
|
| 16 | + private $units = [ '分', '角' ]; |
|
| 17 | + private $grees = [ '元', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟', '万', '拾', '佰' ]; |
|
| 18 | 18 | private $thanOne = false; |
| 19 | 19 | |
| 20 | 20 | public function __construct($money) |
| 21 | 21 | { |
| 22 | - if (!(is_float($money) || is_numeric($money) || is_int($money))) { |
|
| 22 | + if ( ! (is_float($money) || is_numeric($money) || is_int($money))) { |
|
| 23 | 23 | throw new \InvalidArgumentException($money); |
| 24 | 24 | } |
| 25 | 25 | if ($money > 1) { |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | $gree = strlen($intPart) - 1; |
| 52 | 52 | if ($intPart > 0) { |
| 53 | 53 | for ($i = 0; $i < strlen($intPart); ++$i) { |
| 54 | - $num = $intPart[$i]; |
|
| 55 | - $result .= $this->uppers[$num].$this->grees[$gree--]; |
|
| 54 | + $num = $intPart[ $i ]; |
|
| 55 | + $result .= $this->uppers[ $num ] . $this->grees[ $gree -- ]; |
|
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
@@ -80,8 +80,8 @@ discard block |
||
| 80 | 80 | //处理小数部分 |
| 81 | 81 | $unit = strlen($decimalPart) - 1; |
| 82 | 82 | for ($i = 0; $i < strlen($decimalPart); ++$i) { |
| 83 | - $num = $decimalPart[$i]; |
|
| 84 | - $result .= $this->uppers[$num].$this->units[$unit--]; |
|
| 83 | + $num = $decimalPart[ $i ]; |
|
| 84 | + $result .= $this->uppers[ $num ] . $this->units[ $unit -- ]; |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | $result = str_replace('零分', '', $result); |