# Using Float For Currency

**URL:** <https://www.ruby-forum.com/t/using-float-for-currency/50102>\
**Category:** Ruby\
**Created:** [December 13, 2005, 1:05am UTC](https://www.ruby-forum.com/t/using-float-for-currency/50102 "2005-12-13T01:05:30Z")\
**Posts on this page:** 1\
**Page:** 2

<div class="post-metadata">

**Author:** ![HunterSs\_Lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6bbea6/32.png) [@HunterSs\_Lists](https://www.ruby-forum.com/u/HunterSs_Lists)\
**Post date:** [December 17, 2005, 12:04am UTC](https://www.ruby-forum.com/t/using-float-for-currency/50102/21 "2005-12-17T00:04:01Z")

</div>

On 12/16/05, James Edward G. II [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Dec 16, 2005, at 4:39 PM, Stephen W. wrote:
> 
> > Excuse my ignorance, but I’m wondering what BigDecimal does  
> > different than the built-in integer types?
> 
> It doesn’t use floating point arithmetic. That means it is accurate,  
> but slower.

And built-in integer types represent integers, not decimals. 🙂

That does however, bring up the point of using an integer  
representation instead of floating point, eg. manipulating integer  
pennies instead of decimal dollars. If you are certain that integer  
arithmetic – with it’s corresponding truncation; eg. (5 / 3) \* 3  
returns 3, not 5 – is sufficient for your application, it can be  
faster than BigDecimal. AFAIK, BigDecimal is doing this same thing  
(integer representation), behind the scenes, but is slower due to the  
requirements of being flexible in how many decimal places it  
represents.

Another class to look into along these lines – slower but more  
encapsulated than a “roll your own” integer representation, and more  
domain specific than BigDecimal – is the great Money library from  
Tobias  
Lütke:  
[http://dist.leetsoft.com/api/money/](http://dist.leetsoft.com/api/money/)

Jacob F.

[Previous page](https://www.ruby-forum.com/t/using-float-for-currency/50102.md?page=1)
