# Equality Problems

**URL:** <https://www.ruby-forum.com/t/equality-problems/121919>\
**Category:** Rails\
**Created:** [December 2, 2007, 9:51pm UTC](https://www.ruby-forum.com/t/equality-problems/121919 "2007-12-02T21:51:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 2, 2007, 9:51pm UTC](https://www.ruby-forum.com/t/equality-problems/121919/1 "2007-12-02T21:51:50Z")

</div>

Below is a snip of code that I’m having problems with the test in  
the .each method alway will return false and I don’t have a clue why.  
Could someone please help?

@id=params[:id]  
@qty=params[:qty]  
print “ID=”, @id  
print " QTY=", @qty,"\n"  
@cart.items.each{|x| print “ProdID=”,x.product.id,"  
QTY=",x.quantity," “,(x.quantity==(@qty)),”\n"}

Here is the output of the code above

ID=8 QTY=1  
ProdID=8 QTY=1 false  
ProdID=5 QTY=1 false  
ProdID=7 QTY=1 false  
ProdID=8 QTY=2 false  
ProdID=8 QTY=3 false  
ProdID=7 QTY=2 false

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 2, 2007, 11:14pm UTC](https://www.ruby-forum.com/t/equality-problems/121919/2 "2007-12-02T23:14:26Z")

</div>

On 2 Dec 2007, at 20:51, removed\_email\_address@domain.invalid wrote:

> QTY=",x.quantity," “,(x.quantity==(@qty)),”\n"}  
> @qty is a string, x.quantity is an integer and so the 2 are never equal

Fred
