Re: Representing money
Otavio Valadares <[email protected]>
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <CAFqVCPG4NSiDQJkXtioZVJ255AM047c-6uSqxBsG-cCt9t6jXg@mail.gmail.com> |
We use integers "cents" with money <https://github.com/RubyMoney/money> on a multi-currency marketplace and works as expected. I'm grateful. On Tue, Jan 8, 2019 at 1:37 PM Walter Lee Davis <[email protected]> wrote: > > > On Jan 8, 2019, at 10:25 AM, Andy Jones <[email protected]> > wrote: > > > > Re: “Behaviour of round changed?”. > > > > Pardon my curiosity -- what do you use to represent money in your code? > It seems to me that the choices are between: > > > > 1) BigDecimal > > > > 2) Rational > > > > 3) A custom class > > > > To my way of thinking, if you are multi-currency, you almost certainly > want #3; but otherwise it’s down to personal preference? I plumped for > BigDecimal, but I wonder if it would have been easier on me if I had gone > for Rational instead? > > > > > > I use integer "cents" and the Money gem to deal with the localization > details. This works perfectly in a multi-currency Web store. I only ever > store cents, and convert all presentations on the fly into whatever passes > for dollars and cents with a decorator method wrapped around Money: > > ... > Money.new(price_in_cents, currency).format > ... > > Walter > > Unsubscribe: <mailto:[email protected]?subject=unsubscribe> > <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk> > -- Otavio Valadares @ValadaresOtavio https://github.com/OtavioHenrique https://www.linkedin.com/in/otavio-henrique/ https://otaviovaladares.com/ <http://otaviovaladares.com> Unsubscribe: <mailto:[email protected]?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>