2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rubyの小数計算について

Last updated at Posted at 2018-07-11

integerのみの式

[7] pry(main)> (4 + 3) / 2
=> 3

分子を浮動小数点として変換した場合

[8] pry(main)> (4.to_f + 3) / 2
=> 3.5
[9] pry(main)> (4.to_f + 3) / 3
=> 2.3333333333333335
[10] pry(main)> (4 + 3.to_f) / 3
=> 2.3333333333333335
[11] pry(main)> (4 + 3) / 3.to_f
=> 2.3333333333333335

integerとして格納する場合とdecimalとして格納する場合がプロジェクトであったので、注意しないとなと思いました。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?