0
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?

小数点以下の表示

Posted at

整数同士の割り算は、小数点以下が切り捨てられる。

1 / 3
=> 0

直接数値同士を計算する場合は、どちらかの数値に.0をつけることで小数点以下を表示可能。

1.0 / 3
=> 0.3333333333333333

変数を使用して計算する場合はto_fメソッドで整数から少数に変更可能。

a = 1
=> 1

a / 3
=> 0

a.to_f / 3
=> 0.3333333333333333
0
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
0
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?