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

  • Home
  • SEARCH
  • 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 8650809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:54:42+00:00 2026-06-12T13:54:42+00:00

I am a bit confused about a 2-digit decimal gaining an extra 0.000000000000000001 (or

  • 0

I am a bit confused about a 2-digit decimal gaining an extra 0.000000000000000001 (or so) after going into and out of a database.

This is what I’ve done: (Rails 3.2.8)

Created a migration:

class CreateItems < ActiveRecord::Migration
  def change
    create_table :items do |t|
      t.column :price, :decimal, :precision => 16, :scale => 2
    end
  end
end

Created a model:

class Item < ActiveRecord::Base
end

Then:

$ rails c
>> i = Item.new
>> i.price = 9.46
>> i.save
>> Item.first.price
=> #<BigDecimal:46b3768,'0.9460000000 000001E1',27(45)>

It’s a SQLite database, and it all looks ok in there:

$ rails db
>> select * from items;
1|9.46

Note that the only number I’ve noticed this happening with is 9.46.
Where has the extra 0.00000000000001 come from?


Edit I understand that floating point representations of some numbers are not possible without small errors. But why does Item.first.price not equal BigDecimal.new('9.46')? Is SQLite storing a float as opposed to an integer and a number of times it should be divided by 10 (that’s what I’d expect from a decimal column)? Or is there some gotcha in ActiveRecord I’m not aware of with retrieving the value from the DB? See below:

$ rails c
>> decimal = BigDecimal.new('9.46')
>> Item.first.price == decimal
=> false
  • 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-06-12T13:54:43+00:00Added an answer on June 12, 2026 at 1:54 pm

    I am not very familiar with ruby but İnstead of using

    i.price = 9.46
    

    Try using

    i.price = BigDecimal.new('9.46')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit confused about how facebook.logout(context) works. Because even after calling log out,
I am a bit confused about this. If you're building a distributed application, which
I am a bit confused about the nth-of-type pseudo class, and how this is
I am a bit confused about this function definition in Prolog: sample(X,[X|Tail]) :- member(X,Tail).
Im a little bit confused about passing structs into functions. I understand pointers and
I'm a bit confused about stripping out the filename of a URL using bash
I'm a bit confused about this. Does XMLHttpRequest work on a remote URL or
I'm a bit confused about the following. Given this class: public class SomeClassToBeCasted {
I'm a little bit confused about this expression: char *s = abc; Does the
I'm a bit confused about this mass assignment issue. Here's my question Say I

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.