# A Ruby problem calculation problem - please help

**URL:** <https://www.ruby-forum.com/t/a-ruby-problem-calculation-problem-please-help/188704>\
**Category:** Rails\
**Created:** [May 17, 2010, 12:05am UTC](https://www.ruby-forum.com/t/a-ruby-problem-calculation-problem-please-help/188704 "2010-05-17T00:05:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [May 17, 2010, 12:05am UTC](https://www.ruby-forum.com/t/a-ruby-problem-calculation-problem-please-help/188704/1 "2010-05-17T00:05:15Z")

</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

```
  if @tot_hb > 0
    if @tot_hb > 399900
      @bd_disc = 0.80
    elsif @tot_hb > 199900
      @bd_disc = 0.85
    elsif @tot_hb > 99900
      @bd_disc = 0.90
    elsif @tot_hb > 49900
      @bd_disc = 0.95
     end
  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:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [May 17, 2010, 12:40am UTC](https://www.ruby-forum.com/t/a-ruby-problem-calculation-problem-please-help/188704/2 "2010-05-17T00:40:22Z")

</div>

Quoting Paul Jonathan T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> ```
> @bd_disc = 0.80
> 
> ```
> 
> @db\_disc. @client.bd\_rate is a MySql Decimal(3,2) field with a default

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

Jeffrey

---

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [May 17, 2010, 1:43am UTC](https://www.ruby-forum.com/t/a-ruby-problem-calculation-problem-please-help/188704/3 "2010-05-17T01:43:03Z")

</div>

Sorry guys, I got this sorted.
