# Decimal builtin?

**URL:** <https://rubytalk.org/t/decimal-builtin/6537>\
**Category:** ruby-talk\
**Created:** [24 June 2003 08:46 UTC](https://rubytalk.org/t/decimal-builtin/6537 "2003-06-24T08:46:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_Pena\_Botp1](https://avatars.discourse-cdn.com/v4/letter/_/94ad74/32.png) [@\_Pena\_Botp1](https://rubytalk.org/u/_Pena_Botp1)\
**Post date:** [24 June 2003 08:46 UTC](https://rubytalk.org/t/decimal-builtin/6537/1 "2003-06-24T08:46:43Z")

</div>

> > what is [http://www.rubycentral.com/book/ref\_c\_bignum.html](http://www.rubycentral.com/book/ref_c_bignum.html)  
> > or [http://raa.ruby-lang.org/list.rhtml?name=bigfloat](http://raa.ruby-lang.org/list.rhtml?name=bigfloat), no?
> 
> Thanks for your reply Botp, but wouldn’t this still be  
> susceptible to rounding  
> error?

could you site an example so that our ruby friends/hackers can also help?

> Signed,  
> Holden Glova

kind regards -botp

> **···**
>
> Holden Glova [[mailto:dsafari@paradise.net.nz](mailto:dsafari@paradise.net.nz)] wrote:

---

<div class="post-metadata">

**Author:** ![Holden\_Glova](https://avatars.discourse-cdn.com/v4/letter/h/57b2e6/32.png) [@Holden\_Glova](https://rubytalk.org/u/Holden_Glova)\
**Post date:** [24 June 2003 08:54 UTC](https://rubytalk.org/t/decimal-builtin/6537/2 "2003-06-24T08:54:42Z")

</div>

Actually funny you ask because I can’t seem to make the float class provide  
rounding errors. I have been searching on the web but can’t seem to make Ruby  
give me rounding errors. I was under the impressions that floats where always  
inaccurate, is this not the case in Ruby? The reason I ask is because I am  
working on a general Money class. Currently I am backing this with a Fixnum  
in cents, but would prefer to have some sort of decimal type that doesn’t put  
a limit on 2 cent places. Very interesting indeed…

* * *

Signed,  
Holden Glova

> **···**
>
> On Tue, 24 Jun 2003 20:46, Peña, Botp wrote:
> 
> > Holden Glova [[mailto:dsafari@paradise.net.nz](mailto:dsafari@paradise.net.nz)] wrote:
> > 
> > > > what is [http://www.rubycentral.com/book/ref\_c\_bignum.html](http://www.rubycentral.com/book/ref_c_bignum.html)  
> > > > or [http://raa.ruby-lang.org/list.rhtml?name=bigfloat](http://raa.ruby-lang.org/list.rhtml?name=bigfloat), no?
> > > 
> > > Thanks for your reply Botp, but wouldn’t this still be  
> > > susceptible to rounding  
> > > error?
> > 
> > could you site an example so that our ruby friends/hackers can also help?
> > 
> > > Signed,  
> > > Holden Glova
> > 
> > kind regards -botp

---

<div class="post-metadata">

**Author:** ![Tim\_Bates](https://avatars.discourse-cdn.com/v4/letter/t/3da27b/32.png) [@Tim\_Bates](https://rubytalk.org/u/Tim_Bates)\
**Post date:** [24 June 2003 09:41 UTC](https://rubytalk.org/t/decimal-builtin/6537/3 "2003-06-24T09:41:36Z")

</div>

Of course it is, watch:

irb(main):001:0\> x = 1.5e10  
1.5e+10  
irb(main):002:0\> x - 1 == x  
false  
irb(main):003:0\> x = 1.5e20  
1.5e+20  
irb(main):004:0\> x - 1 == x  
true

Now obviously you’re not going to be dealing with amounts of money that  
large, but it shows the inherent inaccuracy in floats.

Tim Bates

> **···**
>
> On Tue, Jun 24, 2003 at 05:54:42PM +0900, Holden Glova wrote:
> 
> > Actually funny you ask because I can’t seem to make the float class provide  
> > rounding errors. I have been searching on the web but can’t seem to make Ruby  
> > give me rounding errors. I was under the impressions that floats where always  
> > inaccurate, is this not the case in Ruby?
> 
> –  
> tim@bates.id.au

---

<div class="post-metadata">

**Author:** ![Tore\_Haug-Warberg](https://avatars.discourse-cdn.com/v4/letter/t/9fc348/32.png) [@Tore\_Haug-Warberg](https://rubytalk.org/u/Tore_Haug-Warberg)\
**Post date:** [24 June 2003 11:27 UTC](https://rubytalk.org/t/decimal-builtin/6537/4 "2003-06-24T11:27:25Z")

</div>

Interesting. I have also noted this and figured out that maybe Matz has  
been clever enough to design the input/output routines of float numbers  
such that the process is reversible (I mean from float to string and back).  
However, I did not trust this and besides it is the issue of reversibility  
from string to float and back (more than, say, 17 digits in the original  
string).

Tore Haug-Warberg

> **···**
>
> At 18:41 24.06.03 +0900, Tim Bates wrote:
> 
> > On Tue, Jun 24, 2003 at 05:54:42PM +0900, Holden Glova wrote:
> > 
> > > Actually funny you ask because I can’t seem to make the float class  
> > > provide  
> > > rounding errors. I have been searching on the web but can’t seem to  
> > > make Ruby  
> > > give me rounding errors. I was under the impressions that floats where  
> > > always  
> > > inaccurate, is this not the case in Ruby?

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [24 June 2003 13:07 UTC](https://rubytalk.org/t/decimal-builtin/6537/5 "2003-06-24T13:07:19Z")

</div>

“Tore Haug-Warberg” [haugwarb@chembio.ntnu.no](mailto:haugwarb@chembio.ntnu.no) schrieb im Newsbeitrag  
news:4.3.2.7.0.20030624115646.00be2100@pop.chembio.ntnu.no…

> > > Actually funny you ask because I can’t seem to make the float class  
> > > provide  
> > > rounding errors. I have been searching on the web but can’t seem to  
> > > make Ruby  
> > > give me rounding errors. I was under the impressions that floats  
> > > where  
> > > always  
> > > inaccurate, is this not the case in Ruby?
> 
> Interesting. I have also noted this and figured out that maybe Matz has  
> been clever enough to design the input/output routines of float numbers  
> such that the process is reversible (I mean from float to string and  
> back).  
> However, I did not trust this and besides it is the issue of  
> reversibility  
> from string to float and back (more than, say, 17 digits in the original  
> string).

There are rounding errors:

irb(main):013:0\> x=1.0  
1.0  
irb(main):014:0\> e=1e-100  
1e-100  
irb(main):015:0\> y=x+e  
1.0  
irb(main):016:0\> y==x  
true  
irb(main):017:0\>

… but obviously y\>x

```
robert

```

> **···**
>
> > At 18:41 24.06.03 +0900, Tim Bates wrote:
> > 
> > > On Tue, Jun 24, 2003 at 05:54:42PM +0900, Holden Glova wrote:
