# Need Help, getting Big Decimal error on a simple	calculation

**URL:** <https://discuss.rubyonrails.org/t/need-help-getting-big-decimal-error-on-a-simple-calculation/22451>\
**Category:** rubyonrails-talk\
**Created:** [December 31, 2007, 3:45pm UTC](https://discuss.rubyonrails.org/t/need-help-getting-big-decimal-error-on-a-simple-calculation/22451 "2007-12-31T15:45:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregory\_Seidman1](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@Gregory\_Seidman1](https://discuss.rubyonrails.org/u/Gregory_Seidman1)\
**Post date:** [December 31, 2007, 3:45pm UTC](https://discuss.rubyonrails.org/t/need-help-getting-big-decimal-error-on-a-simple-calculation/22451/1 "2007-12-31T15:45:51Z")

</div>

> Ok this is driving me nuts.
> 
> Here's my issue in it's most basic form.
> 
> I have a table with a column called amount that was set to :decimal, :precision =\> 8, :scale =\> 2
> 
> In my controller I try to do something like this.
> 
> id = 1 @ticket = Ticket.find(:first, :conditions =\> ['id=?',id]) @ticket.total\_amount += params[:amount] @ticket.direct\_amount += params[:amount] @ticket.save
> 
> This returns an error saying that it 'can't copy BigDecimal'
> 
> If I try to user .to\_f on my total\_amount and direct\_amount and params[:amount] I just end up getting an error about float allocation.
> 
> Any ideas? What info can I provide to make this more helpful?

The actual exception/error messages would be helpful. I'm assuming that the Ticket model's total\_amount and direct\_amount database fields are decimals and therefore ActiveRecord treats them as BigDecimal objects as well as this amount column you mentioned (which table is it in? You don't say). I would expect you to get exceptions like:

TypeError: String can't be coerced into BigDecimal

or

TypeError: nil can't be coerced into BigDecimal

The values in the params hash are always nil, a string, a hash, or an array. Since params comes from the parameters sent as text via HTTP by the web browser, Rails has no way of knowing that params[:amount] should be a number.

Now, I don't see how you would be getting a "can't copy BigDecimal" error given the code you show. You should examine the stacktrace and make sure that the exception is occurring where you think it is. That exception will happen if you try to #dup or #clone a BigDecimal, but I don't see you doing that.

> Thanks for any help.

--Greg
