# ローンの計算
sub calc_loan {
my ($string) = @_;
# 必要ない場合ははずす
$string =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(“C”, hex($1))/eg;
# ローンの計算 ————————————–
# 3.3;1240000;60;0
my ($c4, $c6, $c8, $c10) = split(/;/, $string);
if ($c8 > 0) {
# my $c4; # 実質年利
# my $c6; # お借り入れ額
# my $c8; # 支払い回数
# my $c10; # ボーナス加算額
my $c9 = int ($c8 / 6); # 半年で区切り
# 月利率を計算
my $c77 = $c4/1200;
# 複利金利計算
my $c88 = (1 + $c77)**$c8;
my $c13 = ($c77 * $c88 / ($c88 – 1) * $c8 – 1) * 10000;
$c13 = int ($c13);
$c13 = $c13 / 10000;
# 分割払い手数料
my $f7 = int ($c6 * $c13);
# 分割払い総支払い額
my $f8 = $c6 + $f7;
# 2回目以降のお支払い額(月額)
my $f10 = ($f8 – $c10 * $c9) / $c8;
$f10 = int ($f10 / 100);
$f10 = $f10 * 100;
# 初回支払い額
my $f11 = $c8 – 1;
my $f9 = $f8 – $c10 * $c9 – $f10 * $f11;
# ———————————————–
my $f9_int = int ($f9); my $f10_int = int ($f10);
$f9_int =~ s/(?< =\d)(?=(\d\d\d)+(?!\d))/,/g;
$f10_int =~ s/(?<=\d)(?=(\d\d\d)+(?!\d))/,/g;
my $string_new; if ($c10 > 0) {
$c10 =~ s/(?<=\d)(?=(\d\d\d)+(?!\d))/,/g;
$string_new = '初回 ' . "$f9_int" . '円 / 2回目以降 ' . "$f10_int" . '円' . '/ 年2回ボーナス +' . "$c10" . '円';
} else {$string_new = '初回 ' . "$f9_int" . '円 / 2回目以降 ' . "$f10_int" . '円';}
$string_new =~ s/([^0-9A-Za-z_ ])/'%'.unpack('H2',$1)/ge; # 必要ない場合ははずす
return $string_new;
}
}
1;
参考:http://www110.kir.jp/study/jissen/script3076.html