Advice on handling money

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 C.
http://www.bencurtis.com/
http://www.tesly.com/ – Collaborative test case management
http://www.agilewebdevelopment.com/ – Resources for the Rails community

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

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 :slight_smile:

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 C.
http://www.bencurtis.com/
http://www.tesly.com/ – Collaborative test case management
http://www.agilewebdevelopment.com/ – Resources for the Rails community

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs