Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
#!/usr/bin/perl $test = 1.30733; $test = int($test * 100000); print "test : " , $test ;
テストの結果: 130732
誰かが理由を教えてもらえますか?
int() をスキップした場合、Perl はここで DWIM を実行します。
> $x * 100000 130733
130733/100000 は、1/3 が 10 進数の周期数であるように、2 進数の周期数です。浮動小数点数として格納するには、無限のストレージが必要です。
実際には、130733/100000 より少し小さい値が格納されています。
浮動小数点数を出力するときは常に丸めを使用し、それらを比較するときは常に許容誤差を使用します。