# A Ruby problem calculation problem - please help.

**URL:** <https://discuss.rubyonrails.org/t/a-ruby-problem-calculation-problem-please-help/51686>\
**Category:** rubyonrails-talk\
**Created:** [May 16, 2010, 10:03pm UTC](https://discuss.rubyonrails.org/t/a-ruby-problem-calculation-problem-please-help/51686 "2010-05-16T22:03:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Jonathan\_Thomps](https://avatars.discourse-cdn.com/v4/letter/p/a587f6/32.png) [@Paul\_Jonathan\_Thomps](https://discuss.rubyonrails.org/u/Paul_Jonathan_Thomps)\
**Post date:** [May 16, 2010, 10:03pm UTC](https://discuss.rubyonrails.org/t/a-ruby-problem-calculation-problem-please-help/51686/1 "2010-05-16T22:03:44Z")

</div>

I do not think that my problem is Rails but just my lack of understanding of Ruby.

I am using ruby 1.8.7 (2010-01-10 patchlevel 249) [x86\_64-linux] and Rails 2.3.5

Code: First I evaluate @tot\_hb to decide what discount is to be applied. no problems here

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if @tot\_hb \> 0 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if @tot\_hb \> 399900 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@bd\_disc = 0.80 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif @tot\_hb \> 199900 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@bd\_disc = 0.85 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif @tot\_hb \> 99900 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@bd\_disc = 0.90 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif @tot\_hb \> 49900 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@bd\_disc = 0.95 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

Then I attempt to update @client.bd\_rate with the value that is in @db\_disc. @client.bd\_rate is a MySql Decimal(3,2) field with a default of zero

@client.bd\_rate = @db\_disc

At this point things go pear shaped and I get the message: nil can't be coerced into Fixnum. I know that @db\_disc has a value as if I do a puts the value is displayed as 0.80

It would appear that it is some sort of conversion problem? Help would be very much appreciated.

Regards,

Paul Thompson

---

<div class="post-metadata">

**Author:** ![Jeffrey](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@Jeffrey](https://discuss.rubyonrails.org/u/Jeffrey)\
**Post date:** [May 16, 2010, 10:20pm UTC](https://discuss.rubyonrails.org/t/a-ruby-problem-calculation-problem-please-help/51686/2 "2010-05-16T22:20:28Z")

</div>

Quoting Paul Jonathan Thompson \<rails001@gmail.com\>:

> I do not think that my problem is Rails but just my lack of understanding of Ruby.
> 
> I am using ruby 1.8.7 (2010-01-10 patchlevel 249) [x86\_64-linux] and Rails 2.3.5
> 
> Code: First I evaluate @tot\_hb to decide what discount is to be applied. no problems here
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if @tot\_hb \> 0 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if @tot\_hb \> 399900 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@bd\_disc = 0.80 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif @tot\_hb \> 199900 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@bd\_disc = 0.85 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif @tot\_hb \> 99900 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@bd\_disc = 0.90 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif @tot\_hb \> 49900 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@bd\_disc = 0.95 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
> 
> Then I attempt to update @client.bd\_rate with the value that is in @db\_disc. @client.bd\_rate is a MySql Decimal(3,2) field with a default of zero
> 
> @client.bd\_rate = @db\_disc
> 
> At this point things go pear shaped and I get the message: nil can't be coerced into Fixnum. I know that @db\_disc has a value as if I do a puts the value is displayed as 0.80
> 
> It would appear that it is some sort of conversion problem? Help would be very much appreciated.

Typo in program or e-mail: @bd\_disC OR @db\_disc?

Jeffrey

---

<div class="post-metadata">

**Author:** ![Paul\_Jonathan\_Thomps](https://avatars.discourse-cdn.com/v4/letter/p/a587f6/32.png) [@Paul\_Jonathan\_Thomps](https://discuss.rubyonrails.org/u/Paul_Jonathan_Thomps)\
**Post date:** [May 16, 2010, 11:41pm UTC](https://discuss.rubyonrails.org/t/a-ruby-problem-calculation-problem-please-help/51686/3 "2010-05-16T23:41:49Z")

</div>

Sorry guys, I got this sorted.
