Decimal item gets truncated at DB-storage time

Hi All,

I created a new Expense item. In particular, the value I entered in
the Amount field was 14.99. In the scaffold invocation for this
field, I declared its type to be Decimal.

The log for the creation of this expense record shows
"amount"=>"14.99"

But log for the SQL statement shows:
Create (16.0ms) [0m [0mINSERT INTO `expenses` (`purpose`, `by`,
`updated_at`, `date`, `type`, `amount`, `vendor`, `created_at`)
VALUES('fun', 'RLM', '2010-03-12 22:11:24', '2010-03-12', NULL, 14,
'Ringling Bros', '2010-03-12 22:11:24')
So the amount has been converted to an integer with the decimal
portion of the input truncated.

What’s the best way to resolve this problem?

Thanks in Advance,
Richard

Hi All,

I created a new Expense item. In particular, the value I entered in
the Amount field was 14.99. In the scaffold invocation for this
field, I declared its type to be Decimal.

The log for the creation of this expense record shows
"amount"=>"14.99"

But log for the SQL statement shows:
Create (16.0ms) [0m [0mINSERT INTO `expenses` (`purpose`, `by`,
`updated_at`, `date`, `type`, `amount`, `vendor`, `created_at`)
VALUES('fun', 'RLM', '2010-03-12 22:11:24', '2010-03-12', NULL, 14,
'Ringling Bros', '2010-03-12 22:11:24')
So the amount has been converted to an integer with the decimal
portion of the input truncated.

What’s the best way to resolve this problem?

Thanks in Advance,

Hi Craig,

Thanks for responding.

sql.db
There doesn't appear to be such a critter in my project, although it
was created with script/scaffold

db\schema.db
create_table "expenses", :force => true do |t|
    [snip]
    t.integer "amount", :limit => 10, :precision => 10, :scale =>
0

But just before I logged in right now, the fundamental cause of my
problem struck me:
When I declared expense:decimal in the scaffold, I didn't
declare :scale=>10, :precision=>2, which is what I want. So there's a
new question, I think:
- Can I declare successive migrations where I drop column and then add
column, or
- can I just add those attributes to the column?

I don't care about the any data in there at the moment: it's all toy
data for testing.

I look forward to your additional thoughts.

Best wishes,
Richard

Hi Craig,

Thanks for responding.

sql.db
There doesn't appear to be such a critter in my project, although it
was created with script/scaffold

db\schema.db
create_table "expenses", :force => true do |t|
    [snip]
    t.integer "amount", :limit => 10, :precision => 10, :scale =>
0

But just before I logged in right now, the fundamental cause of my
problem struck me:
When I declared expense:decimal in the scaffold, I didn't
declare :scale=>10, :precision=>2, which is what I want. So there's a
new question, I think:
- Can I declare successive migrations where I drop column and then add
column, or
- can I just add those attributes to the column?

I don't care about the any data in there at the moment: it's all toy
data for testing.

I look forward to your additional thoughts.

Thanks, again, profusely for your response.

< Do you know how to look at your database?