Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mistyrinth
Created November 28, 2018 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mistyrinth/73f01878bc66abe4fd117a0a67eea9a9 to your computer and use it in GitHub Desktop.
Save mistyrinth/73f01878bc66abe4fd117a0a67eea9a9 to your computer and use it in GitHub Desktop.
num1 = 3.1
num2 = 6.5
num3 = -1.2
num4 = -4.5
puts "変換前の数値はそれぞれ #{num1} #{num2} #{num3} #{num4} です。"
puts "切り捨て(to_i)の結果は、 #{num1.to_i} #{num2.to_i} #{num3.to_i} #{num4.to_i} です。"
puts "四捨五入(round)の結果は、 #{num1.round} #{num2.round} #{num3.round} #{num4.round} です。"
puts "切り上げ(ceil)の結果は、 #{num1.ceil} #{num2.ceil} #{num3.ceil} #{num4.ceil} です。"
puts "切り下げ(floor)の結果は、 #{num1.floor} #{num2.floor} #{num3.floor} #{num4.floor} です。"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment