One option:
def maybe_to_int(float) do
truncated = trunc(float)
if truncated == float, do: truncated, else: float
end
Basically just convert the float to an integer. If they evaluate as equal then it must have had no decimal part. If they are no longer equal, return the float.






















