📜  Ruby Float arg() 方法与示例

📅  最后修改于: 2022-05-13 01:55:14.169000             🧑  作者: Mango

Ruby Float arg() 方法与示例

Float arg()是一个浮点类方法,它适用于浮点值,并且对正值和负值的工作方式不同。

示例 #1:

# Ruby code for arg() method
  
# Initializing values
a = -100.7 - 10.4
b = -100 * 2000.0
c = (22 + 7.1) * 4
  
# Printing result
puts "arg value of a : #{a.arg}\n\n"
puts "arg value of b : #{b.arg}\n\n"
puts "arg value of c : #{c.arg}\n\n"

输出 :

arg value of a : 3.141592653589793

arg value of b : 3.141592653589793

arg value of c : 0

示例 #2:

# Ruby code for arg() method
  
# Initializing value
a = -56.23333333
b = 10000.0
c = -(22 + 7.1)
  
# Printing result
puts "arg value of a : #{a.arg}\n\n"
puts "arg value of b : #{b.arg}\n\n"
puts "arg value of c : #{c.arg}\n\n"

输出 :

arg value of a : 3.141592653589793

arg value of b : 0

arg value of c : 3.141592653589793