# Jruby precision issue with reading float values in mysql db

**URL:** <https://www.ruby-forum.com/t/jruby-precision-issue-with-reading-float-values-in-mysql-db/168919>\
**Category:** Ruby\
**Created:** [May 27, 2009, 11:41am UTC](https://www.ruby-forum.com/t/jruby-precision-issue-with-reading-float-values-in-mysql-db/168919 "2009-05-27T11:41:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pradeepgatram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c6cbf5/32.png) [@pradeepgatram](https://www.ruby-forum.com/u/pradeepgatram)\
**Post date:** [May 27, 2009, 11:41am UTC](https://www.ruby-forum.com/t/jruby-precision-issue-with-reading-float-values-in-mysql-db/168919/1 "2009-05-27T11:41:16Z")

</div>

Hi,

I was trying to upgrade from 1.1.6 to 1.2.0 and noticed a strange  
issue with floats. In Jruby 1.2.0, a float like 2.52342 is read as  
2.52342009544373 from the DB.

A few steps to reproduce this.

1. Migration: t.float :reading
2. Fixture: reading: 2.52342
3. Run script/console

jruby script/console  
Loading development environment (Rails 2.2.2)

> > Foo.first.reading  
> > =\> 2.52342009544373

Any idea if this has been logged as a bug or if there is a workaround?

---

<div class="post-metadata">

**Author:** ![pradeepgatram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c6cbf5/32.png) [@pradeepgatram](https://www.ruby-forum.com/u/pradeepgatram)\
**Post date:** [May 28, 2009, 8:36am UTC](https://www.ruby-forum.com/t/jruby-precision-issue-with-reading-float-values-in-mysql-db/168919/2 "2009-05-28T08:36:42Z")

</div>

The issue persists with both 1.3.0 RC1 & RC2.

---

<div class="post-metadata">

**Author:** ![pradeepgatram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c6cbf5/32.png) [@pradeepgatram](https://www.ruby-forum.com/u/pradeepgatram)\
**Post date:** [May 28, 2009, 7:21pm UTC](https://www.ruby-forum.com/t/jruby-precision-issue-with-reading-float-values-in-mysql-db/168919/3 "2009-05-28T19:21:16Z")

</div>

It seems the problem is that we’re showing the actual machine precision  
here. Floats are rarely 100% accurate, and this is likely a case where  
it’s losing some accuracy going into or coming out of the database. It’s  
possible there’s a bug somewhere, but expecting floats to always be an  
exact amount generally leads to bugs.

At any rate, can you file an issue for this in JRuby’s bug tracker, and  
if it’s valid we’ll try to fix it 🙂
