Skip to content
Related Articles

Related Articles

Ruby Float negative() method with example
  • Last Updated : 07 Jan, 2020
GeeksforGeeks - Summer Carnival Banner

Float negative() is a float class method which checks whether the float value is negative.

Syntax: float.negative()

Parameter: float value which is to be checked

Return: Boolean value return false – if value is positive and return true – if value is negative

Example #1:






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

Output :

a is negative : true

b is negative : true

c is negative : false

Example #2:




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

Output :

a is negative : true

b is negative : false

c is negative : true

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :