title: Handling BigDecimal trailing zero's Ruby
body: <p>I am using <code>BigDecimal</code> values in my app as there are calculations to be made for goods in a shopping cart, I read that <code>BigDecimal</code> is preferred for this, compared to say integers or floats?</p>
  
  <p>There is one scenario which I would like to address. When I have this for example</p>
  
  <pre><code>amount = BigDecimal.new("28.99")
  amount      #=&gt; #&lt;BigDecimal:51d3120,'0.2899E2',18(18)&gt;
  amount.to_s #=&gt; "28.99"
  amount.to_f #=&gt; 28.99
  </code></pre>
  
  <p>Which so far is expected behavior but when I do the following</p>
  
  <pre><code>amount = BigDecimal.new("28.00") || amount = BigDecimal.new("28") 
  amount.to_s #=&gt; "28.0"
  amount.to_f #=&gt; 28.0
  </code></pre>
  
  <p>Is this intended behavior ? In my db I have set the scale and precision</p>
  
  <pre><code>t.decimal :price, precision: 30, scale: 2
  </code></pre>
  
  <p>When I have a value of <code>28.00</code> saved in the database I would like to show in my view <code>28.00</code> and not <code>28.0</code></p>
  
  <p>Update</p>
  
  <p>Just come across this post on SO <a href="https://stackoverflow.com/questions/24892378/how-to-convert-a-ruby-bigdecimal-to-a-2-decimal-place-string">How to convert a ruby BigDecimal to a 2-decimal place string?</a> the solution being </p>
  
  <pre><code>v = BigDecimal("28.00")
  v.truncate.to_s + '.' + sprintf('%02d', (v.frac * 100).truncate)
  </code></pre>
  
  <p>I guess this is the only way to handle it ?</p>