title: Ruby round float to_int if whole number
body: <p>In ruby, I want to convert a float to an int if it's a whole number.  For example</p>
  
  <pre><code>a = 1.0
  b = 2.5
  
  a.to_int_if_whole # =&gt; 1
  b.to_int_if_whole # =&gt; 2.5
  </code></pre>
  
  <p>Basically I'm trying to avoid displaying ".0" on any number that doesn't have a decimal.  I'm looking for an elegant (or built-in) way to do </p>
  
  <pre><code>def to_int_if_whole(float)
    (float % 1 == 0) ? float.to_i : float
  end
  </code></pre>