This time, I will write how to check if the value of a variable is an integer. As an example, let a be an integer or a variable you want to see, as follows.
if a - a.to_i == 0
puts "This is an integer"
else
puts "This is a non-integer"
end
There is a part called a.to_i here, but in the case of a = 1.1, it means that it is converted to an integer (rounded down after the decimal point), and 1 (when calculating as a real number, only the number after the decimal point is 0) Tsuku → Now it is 1.0).
a - a.to_i = 1.1 - 1.0 = 0.1 (cannot be 0!)
Therefore, I think there is one way to see if the square root is a real number.
Recommended Posts