+ 8

Is it allowed to use float in the range?

I tried to use floats instead of integers in the ranges, I found that: - If low value is integer and high value is float it works. - While if low value is a float there is an error. If the value of the float is equal to an integer (e.g.: 7.0) we'll have different behavior if 2 (..) or three (...) dots are used. If the value of the float is not equal to an integer (e.g.: 7.1) we'll have the same behavior if 2 (..) or three (...) dots are used. You can check the following code: https://code.sololearn.com/cl91PYmihaTl/#rb Is it working only on Code Playground, or will it work on all environments?

2nd Jun 2017, 6:39 PM
Daniele Gaito
Daniele Gaito - avatar
1 ответ
+ 3
For more Range Info: https://ruby-doc.org/core-2.4.1/Range.html The starting of ranges is not allowed as floating value to iterate, it doesn't have 'succ' method that's why Float Error occurs. you can convert to integer or use step method to iterate over float data. Using step method iteration over floating data is possible https://code.sololearn.com/cN65CBMBVaU6/?ref=app
26th Jun 2017, 6:35 AM
Piyush Goyani
Piyush Goyani - avatar