Hi, I''m trying to handle money within an online store I''m building and I''m very stuck. I understand that using a float in the db is bad because of "rounding errors", and that storing the price as an integer is the best way forward. I know this has been brought up before on the list and I have search the archives but can''t find a good way forward. What''s the simplest way of handling this situation? From what I''ve read on various blogs, there doesn''t seem to be a definitive way of dealing with money. I''ve seen and tried to use the Money library, but I''ve not had much luck with it. Any ideas? Thanks for any help, Jordan
Here''s a handy plugin for working with money stored in pennies as integers in the database: http://agilewebdevelopment.com/plugins/ dollars_and_cents -- Benjamin Curtis http://www.bencurtis.com/ http://www.tesly.com/ -- Collaborative test case management http://www.agilewebdevelopment.com/ -- Resources for the Rails community On Jul 10, 2006, at 7:12 AM, Jordan Elver wrote:> Hi, > I''m trying to handle money within an online store I''m building and I''m > very stuck. I understand that using a float in the db is bad because > of "rounding errors", and that storing the price as an integer is the > best way forward. I know this has been brought up before on the list > and I have search the archives but can''t find a good way forward. > > What''s the simplest way of handling this situation? From what I''ve > read on various blogs, there doesn''t seem to be a definitive way of > dealing with money. I''ve seen and tried to use the Money library, but > I''ve not had much luck with it. > > Any ideas? > > Thanks for any help, > Jordan > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
> Here''s a handy plugin for working with money stored in pennies as > integers in the database: http://agilewebdevelopment.com/plugins/ > dollars_and_centsYeah, I''ve seen that one, but what I don''t understand is how storing prices as integers, but accessing them as floats will help? I thought the problem with accessing them as floats was that you get in precise numbers when doing calculations etc? How does this plugin get around that problem? Thanks for the response, Jordan
Having not used the plugin (I did my stuff in ints and did the display conversions myself before this plugin was released), I would guess you could do all your math with the *_in_cents fields. -- Benjamin Curtis http://www.bencurtis.com/ http://www.tesly.com/ -- Collaborative test case management http://www.agilewebdevelopment.com/ -- Resources for the Rails community On Jul 10, 2006, at 7:44 AM, Jordan Elver wrote:>> Here''s a handy plugin for working with money stored in pennies as >> integers in the database: http://agilewebdevelopment.com/plugins/ >> dollars_and_cents > > Yeah, I''ve seen that one, but what I don''t understand is how storing > prices as integers, but accessing them as floats will help? I thought > the problem with accessing them as floats was that you get in precise > numbers when doing calculations etc? How does this plugin get around > that problem? > > Thanks for the response, > Jordan > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
> Having not used the plugin (I did my stuff in ints and did the > display conversions myself before this plugin was released), I would > guess you could do all your math with the *_in_cents fields.Ah, I see. Simple when you think about it :)