Conditional Float Precision

I’m trying to figure out the best way (and hopefully leanest) to
conditionally have precision to a float number.

Here’s what I’m doing…

I have a float (which has a default precision of 1) so like 250.0

What I want to do is have the precision go to 0 if the value after
the . is 0 = so 250.0 would show as 250, but 250.5 would show 250.5.

Thoughts? Thanks.

Write a simple helper method that returns the rounded number if
different

def display_float(num)
if num.floor < num
return num
end
return num.floor
end

Brewpoo - sweet! Thanks.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs