Horje
Ruby Float positive() method with example

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

Syntax: float.positive() Parameter: float value which is to be checked Return: Boolean value return true – if value is positive or return false – if value is negative

Example #1: 

Ruby

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

Output :

a is positive : false

b is positive : false

c is positive : true

Example #2: 

Ruby

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

Output : 

a is positive : false

b is positive : true

c is positive : false



Reffered: https://www.geeksforgeeks.org


Ruby

Related
Ruby | Float numerator() method Ruby | Float numerator() method
Ruby Float divmod() method with example Ruby Float divmod() method with example
Ruby Float negative() method with example Ruby Float negative() method with example
Ruby Float fdiv() method with example Ruby Float fdiv() method with example
Ruby Float magnitude() method with example Ruby Float magnitude() method with example

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
8