Yeah, now i can confidently use this to check a string is float
def is_float?(fl)
fl =~ /(^(\d+)(\.)?(\d+)?)|(^(\d+)?(\.)(\d+))/
end def is_float?(fl)
fl =~ /(^(\d+)(\.)?(\d+)?)|(^(\d+)?(\.)(\d+))/
end- 1.4
- -1.4
- .4
- -.4
- 1.
- -1.
... plus exponents, also you don't need a decimal point if there's an exponent
Won't Ruby parse a string into a float? I would just use that and check for an error unless your requirements are different.
Doesn't Ruby allow scientific notation for floats?
>> 6.626e-34 < 9.109e-31
=> true /(^(\d+)(\.)?(\d+)?)|(^(\.)(\d+))/