richiepop2
richiepop2

Reputation: 348

number_with_precision called on attribute

My boli model has an attribute current, which is an integer.

When I publish the current value, it's not showing the decimal points.

And when I add number_with_precision it shows zeros instead of the actual numbers.

The number in the column is 10.78. When I publish the number is shows 10.00.

Below is my html code. I've also tried number_to_currency, but with the same results. Any idea how I can get the current attribute to show the decimal points?

  <div class="ratings"> 
    <b>Current BOLI:</b> 
    <%=number_with_precision(boli.current, precision: 2) %> 
  </div>

Thank you ruby community.

Upvotes: 0

Views: 91

Answers (1)

MZaragoza
MZaragoza

Reputation: 10111

in this case I would make sure not to use a integer but instead to use a decimal.

change_column :bolis, :current, :decimal

I believe that is all you should need and you will be ok. I would also then recorded in looking at the precision and scale option that go with decimal

  • precision Defines the precision for the decimal fields, representing the total number of digits in the number.

  • scale Defines the scale for the decimal fields, representing the number of digits after the decimal point.

for more info look at http://edgeguides.rubyonrails.org/active_record_migrations.html#column-modifiers

Upvotes: 1

Related Questions