# Problem with decimal data type

**URL:** <https://www.ruby-forum.com/t/problem-with-decimal-data-type/71325>\
**Category:** Rails\
**Created:** [October 6, 2006, 11:54pm UTC](https://www.ruby-forum.com/t/problem-with-decimal-data-type/71325 "2006-10-06T23:54:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [October 6, 2006, 11:54pm UTC](https://www.ruby-forum.com/t/problem-with-decimal-data-type/71325/1 "2006-10-06T23:54:03Z")

</div>

I ran a migration with the following:

create\_table :userlevels do |t|  
# t.column :name, :string  
t.column :usertype, :string, :limit =\> 15  
t.column :userlevel, :string, :limit =\> 15  
t.column :price, :decimal, :precision =\> 7, :scale =\> 2  
end

The problem is the decimal column. rake ignored the precision and scale  
parameters and defined it as decimal(10,0). What’s the magic words to  
actually get rake to create a decimal column with decimal places? I’m  
sure it’s obvious, but I don’t see it.

Thanks in advance  
—Michael

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [October 7, 2006, 6:43pm UTC](https://www.ruby-forum.com/t/problem-with-decimal-data-type/71325/2 "2006-10-07T18:43:37Z")

</div>

The column type :decimal didn’t work in my installation, so I worked  
around it with a plain MySQL statement in the migration script instead  
of your t.column statement:  
t.column :price, :float  
execute “alter table products modify column price decimal(8,2)”

Michael S. wrote:

> I ran a migration with the following:
> 
> create\_table :userlevels do |t|  
> # t.column :name, :string  
> t.column :usertype, :string, :limit =\> 15  
> t.column :userlevel, :string, :limit =\> 15  
> t.column :price, :decimal, :precision =\> 7, :scale =\> 2  
> end
> 
> The problem is the decimal column. rake ignored the precision and scale  
> parameters and defined it as decimal(10,0). What’s the magic words to  
> actually get rake to create a decimal column with decimal places? I’m  
> sure it’s obvious, but I don’t see it.
> 
> Thanks in advance  
> —Michael

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [October 7, 2006, 9:56pm UTC](https://www.ruby-forum.com/t/problem-with-decimal-data-type/71325/3 "2006-10-07T21:56:46Z")

</div>

Thanks man, that did the trick !

Simple.

Groetjes

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [October 8, 2006, 1:03pm UTC](https://www.ruby-forum.com/t/problem-with-decimal-data-type/71325/4 "2006-10-08T13:03:54Z")

</div>

On 10/6/06, Michael S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> The problem is the decimal column. rake ignored the precision and scale  
> parameters and defined it as decimal(10,0). What’s the magic words to  
> actually get rake to create a decimal column with decimal places? I’m  
> sure it’s obvious, but I don’t see it.

You need to be running edge rails. Decimal support isn’t included in  
the stable release.

Isak
