68user's page 掲示板

Prev< No. 2942> Next  [最新発言に戻る] [過去ログ一覧]
No. 2942 # ふくし [E-mail] 2002/11/21 (木) 17:30:37
>>2940 名無し
さん、ありがとうございます。

sprintf は四捨五入なんですね。
ということはあらかじめ 0.005 を引いておけばよい?
−−−−−−−−−−プログラム−−−−−−−−−−−−−−>8
#! perl

while (<DATA>) {
                chomp;
                $tanka = $_; # ドル
                print "tanka = $tanka ";
                $tanka -= 0.005; # 切り捨てたいから
                $kosuu = 1; # 個
                $uriage100 = $tanka * $kosuu * 100; # 売上の 100 倍
                $uriage = $uriage100 / 100;
                $uriage = sprintf "%.2f", $uriage;
                print "uriage = $uriage\n";
}
−−−−−−−−−−プログラム終わり−−−−−−−−−−−>8
実行結果。
> keisan
tanka = 10000.88 uriage = 10000.88
tanka = 10000.881 uriage = 10000.88
tanka = 10000.882 uriage = 10000.88
tanka = 10000.883 uriage = 10000.88
tanka = 10000.884 uriage = 10000.88
tanka = 10000.885 uriage = 10000.88
tanka = 10000.886 uriage = 10000.88
tanka = 10000.887 uriage = 10000.88
tanka = 10000.888 uriage = 10000.88
tanka = 10000.889 uriage = 10000.88

なんかできてるっぽい、、?

__DATA__
10000.88
10000.881
10000.882
10000.883
10000.884
10000.885
10000.886
10000.887
10000.888
10000.889

Prev< No. 2942> Next  [最新発言に戻る] [過去ログ一覧]