<?php
function rmb_format($money = 0, $is_round = true, $int_unit = '元') {
$chs = array (0, '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
$uni = array ('', '拾', '佰', '仟' );
$dec_uni = array ('角', '分' );
$exp = array ('','万','亿');
$res = '';
$parts = explode ( '.', $money, 2 );
$int = isset ( $parts [0] ) ? strval ( $parts [0] ) : 0;
$dec = isset ( $parts [1] ) ? strval ( $parts [1] ) : '';
$dec_len = strlen ( $dec );
if (isset ( $parts [1] ) && $dec_len > 2) {
$dec = $is_round ? substr ( strrchr ( strval ( round ( floatval ( "0." . $dec ), 2 ) ), '.' ), 1 ) : substr ( $parts [1], 0, 2 );
}
if (empty ( $int ) && empty ( $dec )) {
return '零';
}
for($i = strlen ( $int ) - 1, $t = 0; $i >= 0; $t++) {
$str = '';
for($j = 0; $j < 4 && $i >= 0; $j ++, $i --) {
$u = $int{$i} > 0 ? $uni [$j] : '';
$str = $chs [$int {$i}] . $u . $str;
}
$str = rtrim ( $str, '0' );
$str = preg_replace ( "/0+/", "零", $str );
$u2 = $str != '' ? $exp [$t] : '';
$res = $str . $u2 . $res;
}
$dec = rtrim ( $dec, '0' );
if (!empty ( $dec )) {
$res .= $int_unit;
$cnt = strlen ( $dec );
for($i = 0; $i < $cnt; $i ++) {
$u = $dec {$i} > 0 ? $dec_uni [$i] : '';
$res .= $chs [$dec {$i}] . $u;
}
if ($cnt == 1) $res .= '整';
$res = rtrim ( $res, '0' );
$res = preg_replace ( "/0+/", "零", $res );
} else {
$res .= $int_unit . '整';
}
return $res;
}
function interest_day($money, $annualInterestRate, $day)
{
$interestRate = $annualInterestRate / 365;
return $money * $interestRate * $day;
}
function interest_count($money, $annualInterestRate, $month, $type = 0)
{
$interestRate = $annualInterestRate / 12;
$res = array ();
if ($type == 0) {
$interest = $money * $interestRate * $month;
$res [] = array ('total' => $money + $interest,'money' => $money,'interest' => $interest,'nper' => 1 );
} elseif ($type == 1) {
$trate = $interestRate + 1;
$res = array ();
for($i = 1; $i <= $month; $i ++) {
$a = $money * $interestRate * pow ( $trate, $i - 1 );
$b = pow ( $trate, $month ) - 1;
$c = $money * $interestRate * (pow ( $trate, $month ) - pow ( $trate, $i - 1 ));
$res [$i] ['money'] = round ( $a / $b, 2 );
$res [$i] ['interest'] = round ( $c / $b, 2 );
$res [$i] ['nper'] = $i;
$res [$i] ['total'] = round ( $res [$i] ['money'] + $res [$i] ['interest'], 2 );
}
} elseif ($type == 2) {
$principal = $money / $month;
$res = array ();
for($i = 1; $i <= $month; $i ++) {
$interest = $money * $interestRate;
$res [$i] = array ('total' => $principal + $interest,'money' => $principal,'interest' => $interest,'nper' => $i,'diminishing' => $principal * $interestRate );
$money = $money - $principal;
}
} elseif ($type == 3) {
for($i = 1; $i <= $month; $i ++) {
$interest = $money * $interestRate;
if ($i == $month) {
$res [$i] = array ('total' => $money + $interest,'money' => $money,'interest' => $interest,'nper' => $i );
} else {
$res [$i] = array ('total' => $interest,'money' => 0,'interest' => $interest,'nper' => $i );
}
}
}
return $res;
}
function aaa($cash, $rate, $month)
{
$rate = $rate / 12;
$c = $cash * $rate * $month;
$res = [ 'total' => $cash + $c,'cash' => $cash,'rate' => $c ];
return $c;
}
function bbb($cash, $rate, $month)
{
$rate = $rate / 12;
$trate = $rate + 1;
$a = $cash * $rate * pow ( $trate, $month );
$b = pow ( $trate, $month ) - 1;
$P = round ( $a / $b, 2 );
$res = array ();
for($i = 1; $i <= $month; $i ++) {
$a = $cash * $rate * pow ( $trate, $i - 1 );
$b = pow ( $trate, $month ) - 1;
$c = $cash * $rate * (pow ( $trate, $month ) - pow ( $trate, $i - 1 ));
$res [$i] ['cash'] = round ( $a / $b, 2 );
$res [$i] ['rate'] = round ( $c / $b, 2 );
$res [$i] ['total'] = round ( $res [$i] ['cash'] + $res [$i] ['rate'], 2 );
}
return $res;
}
function ccc($cash, $rate, $month)
{
$rate = $rate / 12;
$a = $cash / $month;
$res = array ();
for($i = 1; $i <= $month; $i ++) {
$d = $cash * $rate;
$cash = $cash - $a;
$res [$i] = [ 'total' => $a + $d,'cash' => $a,'rate' => $d ];
}
return $res;
}
function ddd($cash, $rate, $month)
{
$rate = $rate / 12;
$res = array ();
for($i = 1; $i <= $month; $i ++) {
$c = $cash * $rate;
if ($i == $month) {
$res [$i] = [ 'total' => $cash + $c,'cash' => $cash,'rate' => $c ];
} else {
$res [$i] = [ 'total' => $c,'cash' => 0,'rate' => $c ];
}
}
return $res;
}
function eee($cash, $rate, $month)
{
$res = array ();
for($i = 1; $i <= $month; $i ++) {
$c = $cash * $rate;
if ($i == $month) {
$res [$i] = [ 'total' => $cash + $c,'cash' => $cash,'rate' => $c ];
} else {
$res [$i] = [ 'total' => $c,'cash' => 0,'rate' => $c ];
}
}
return $res;
}
function amount_format($amount)
{
return number_format ( $amount, 2, '.', ',' );
}