Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7602067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:19:06+00:00 2026-05-30T23:19:06+00:00

I have the following model/table in rails3/postgreSQL: create_table admin_reports, :force => true do |t|

  • 0

I have the following model/table in rails3/postgreSQL:

create_table "admin_reports", :force => true do |t|
  t.string   "report"
  t.decimal  "result"
  t.string   "result_type"
  t.datetime "created_at"
  t.datetime "updated_at"
end

On production, AdminReports.result is not storing the decimal but rather a hash:

AdminReport.last

=> #<AdminReport id: 4, report: "dau", result: #<BigDecimal:cbca0f0,'0.8E1',4(8)>, result_type: "percentage", created_at: "2012-02-28 22:05:15", updated_at: "2012-02-28 22:05:15">

Where I would expect to see:

AdminReport.last

=> #<AdminReport id: 4, report: "dau", result: 10.10, result_type: "percentage", created_at: "2012-02-28 22:05:15", updated_at: "2012-02-28 22:05:15">

In the rails console, even if I try to set the result field manually like so:

@a = AdminReport.last
@a.result = 8.89
@a.save

It still shows AdminReport.result as a BigDecimal hash. Any ideas what’s going on here?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:19:07+00:00Added an answer on May 30, 2026 at 11:19 pm

    You’re using a decimal column:

    create_table "admin_reports", :force => true do |t|
      #...
      t.decimal  "result"
      #...
    end
    

    That usually means that you want to use a fixed number of decimal places so you probably want to specify the :precision and :scale options as well. When ActiveRecord sees a decimal column, it converts the value to Ruby’s BigDecimal so that you can maintain the desired number of decimal places while in Ruby-land; if AR used a floating point value then you’d run into all the usual floating point problems and you could end up pulling one value out of the database and putting a different one back without intentionally changing it, using BigDecimal avoids the problem entirely.

    When you see this:

    #<BigDecimal:cbca0f0,'0.8E1',4(8)>
    

    You’re just seeing the standard inspect output from BigDecimal. If you use to_s (or "#{...}"), you’ll see something more familiar.

    So there’s nothing to worry about. If you need to use non-integer arithmetic but don’t want all the problems of floating point then a decimal column (with :precision and :scale) is the right choice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following model structure: class Container(models.Model): pass class Generic(models.Model): name = models.CharacterField(unique=True)
So I have the following model: public class Person { public String FirstName {
I have the following Rails model: class CreateFoo < ActiveRecord::Migration def self.up create_table :foo
I have a following model: class Car(models.Model): make = models.CharField(max_length=40) mileage_limit = models.IntegerField() mileage
I have the following Model pattern: public abstract class PARENTCLASS {...} public class CHILD_A_CLASS
I have the following model and instance: class Bashable(models.Model): name = models.CharField(max_length=100) >>> foo
I have the following model: class User: name = models.CharField( max_length = 200 )
I have the following model association: a student model and has_many scores. I need
I have the following model setup - a User is interested in projects in
I have the following Model and Controller files, and when i visit this url,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.