My application deals a lot with money. I''m currently using BigDecimal (SQL decimal) to represent money, which is kind of a hassle because of all the BigDecimal.new(''...'') calls. For this reason, I''m considering switching over to float. Is there any reason not to do so? Eric --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 3 Jun 2008, at 22:47, Eric LIn wrote:> My application deals a lot with money. I''m currently using BigDecimal > (SQL decimal) to represent money, which is kind of a hassle because of > all the BigDecimal.new(''...'') calls. For this reason, I''m considering > switching over to float. Is there any reason not to do so?There are millions of rounding-off reasons not to do so. Or use integers and fixed point. This is actually one of the areas where I severely miss the automatic variable-precision handling of numbers in Smalltalk. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you''ve used a decimal datatype [with the necessary precision and scope options] in your db, Rails should be able to handle managing the decimal part for you. You might still need to use number_to_currency and formatting in your views but AFAIK Rails is able to handle the conversions on its own and save you the work. RSL --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
zomg rsl posts on the rubyonrails-talk mailing list! Anyway, For money I use a single integer field, sometimes cost_in_cents, and then use the Money gem to parse that to a real format. Thankfully I haven''t yet to deal with fractions of a cent. If you''re not worried about fractions of a cent, then go for the Money gem and an integer field. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Eric LIn wrote:> My application deals a lot with money. I''m currently using BigDecimal > (SQL decimal) to represent money, which is kind of a hassle because of > all the BigDecimal.new(''...'') calls. For this reason, I''m considering > switching over to float. Is there any reason not to do so? > > EricThe money gem and the rails_money plugin are great. You put, say "cost_in_cents" in your model as an integer. Then you can reference the "cost" method and it will return a money object, all the while storing as an integer. cost.to_s returns a currency-formatted string of the amount. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
i haven''t worked with currency a lot myself. what are the benefits of using the money gem over decimal datatype? or just another tool? i''ve seen it touted before and wondered. no place like the mailing list to get some perspectives. RSL On Tue, Jun 3, 2008 at 9:50 PM, Cayce Balara < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Eric LIn wrote: > > My application deals a lot with money. I''m currently using BigDecimal > > (SQL decimal) to represent money, which is kind of a hassle because of > > all the BigDecimal.new(''...'') calls. For this reason, I''m considering > > switching over to float. Is there any reason not to do so? > > > > Eric > > The money gem and the rails_money plugin are great. > > You put, say "cost_in_cents" in your model as an integer. Then you can > reference the "cost" method and it will return a money object, all the > while storing as an integer. cost.to_s returns a currency-formatted > string of the amount. > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Well, my use of money gem and integer for currency amounts stems from the fact that the ActiveMerchant plugin works with those. Over time, though, I''ve found it to be a very dev-friendly solution. I''m not sure if I can come up with an overriding, grand reason for using one or the other, tbh. RSL ___ wrote:> i haven''t worked with currency a lot myself. what are the benefits of > using > the money gem over decimal datatype? or just another tool? i''ve seen it > touted before and wondered. no place like the mailing list to get some > perspectives. > > RSL > > On Tue, Jun 3, 2008 at 9:50 PM, Cayce Balara <-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
disclaimer needed - I haven''t worked with global currency issues and thus need to wrap my comments with <USD> </USD>. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---