# Advice on handling money

**URL:** <https://www.ruby-forum.com/t/advice-on-handling-money/97784>\
**Category:** Rails\
**Created:** [July 10, 2006, 4:15pm UTC](https://www.ruby-forum.com/t/advice-on-handling-money/97784 "2006-07-10T16:15:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jordelver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jordelver](https://www.ruby-forum.com/u/jordelver)\
**Post date:** [July 10, 2006, 4:15pm UTC](https://www.ruby-forum.com/t/advice-on-handling-money/97784/1 "2006-07-10T16:15:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jordelver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jordelver](https://www.ruby-forum.com/u/jordelver)\
**Post date:** [July 10, 2006, 4:35pm UTC](https://www.ruby-forum.com/t/advice-on-handling-money/97784/2 "2006-07-10T16:35:54Z")

</div>

Here’s a handy plugin for working with money stored in pennies as  
integers in the database: [http://agilewebdevelopment.com/plugins/](http://agilewebdevelopment.com/plugins/)  
dollars\_and\_cents

–  
Benjamin C.  
[http://www.bencurtis.com/](http://www.bencurtis.com/)  
[http://www.tesly.com/](http://www.tesly.com/) – Collaborative test case management  
[http://www.agilewebdevelopment.com/](http://www.agilewebdevelopment.com/) – Resources for the Rails community

---

<div class="post-metadata">

**Author:** ![jordelver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jordelver](https://www.ruby-forum.com/u/jordelver)\
**Post date:** [July 10, 2006, 4:46pm UTC](https://www.ruby-forum.com/t/advice-on-handling-money/97784/3 "2006-07-10T16:46:03Z")

</div>

> Here’s a handy plugin for working with money stored in pennies as  
> integers in the database: [http://agilewebdevelopment.com/plugins/](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

---

<div class="post-metadata">

**Author:** ![jordelver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jordelver](https://www.ruby-forum.com/u/jordelver)\
**Post date:** [July 11, 2006, 11:27am UTC](https://www.ruby-forum.com/t/advice-on-handling-money/97784/4 "2006-07-11T11:27:54Z")

</div>

> 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 🙂

---

<div class="post-metadata">

**Author:** ![jordelver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jordelver](https://www.ruby-forum.com/u/jordelver)\
**Post date:** [July 11, 2006, 4:43am UTC](https://www.ruby-forum.com/t/advice-on-handling-money/97784/5 "2006-07-11T04:43:12Z")

</div>

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