Numbers greater than 0 are positive numbers. We can check if a number is greater than 0 by using the positive?
method. This method returns either true
or false
.
float_value.positive?
float_value: This is the float value that we want to check to see if it is greater than 0.
The result of this method is always a boolean value.
If the float_value
is greater than 0, then true
is returned. However, if the float_value
is not greater than 0, then false
is returned.
# create some valuesf1 = 3.444f2 = 0.0f3 = 0.3f4 = 100 / 0.0# check if greater than 0# and print resultsputs f1.positive? # trueputs f2.positive? # falseputs f3.positive? # trueputs f4.positive? # true
f1
, f2
, f3
, and f4
.positive?
method on the float values we created, and we print the returned values to the console.