Skip to content
Related Articles
Open in App
Not now

Related Articles

Ruby Float nan?() method with example

Improve Article
Save Article
Like Article
  • Last Updated : 13 Jan, 2022
Improve Article
Save Article
Like Article

Float nan?() is a float class method that checks whether the value is ‘not a number’. ‘Not A Number’ means an invalid IEEE floating-point number.

Syntax: float.nan?()
Parameter: float value to be passed
Return: Return true – if the value is ‘not a number’ otherwise return false

Example #1:  

Ruby




# Ruby program for nan?() method
   
# Initializing value
a = 0.0
b = 0.0.modulo(4.0)
   
# Printing result
puts "a is not_a_number : #{a.nan?}\n\n"
puts "b is not_a_number : #{b.nan?}\n\n"

Output : 

a is not_a_number : false

b is not_a_number : false

Example #2: 

Ruby




# Ruby program for nan?() method
   
# Initializing value
a = 26.00
b = 8.0
   
# Printing Result
puts "a is not_a_number : #{a.nan?}\n\n"
puts "b is not_a_number : #{b.nan?}\n\n"

Output : 

a is not_a_number : false

b is not_a_number : false

 

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!