# Rails 3 and saving decimal values from a form

**URL:** <https://www.ruby-forum.com/t/rails-3-and-saving-decimal-values-from-a-form/206983>\
**Category:** Rails\
**Created:** [May 15, 2011, 6:27am UTC](https://www.ruby-forum.com/t/rails-3-and-saving-decimal-values-from-a-form/206983 "2011-05-15T06:27:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [May 15, 2011, 6:27am UTC](https://www.ruby-forum.com/t/rails-3-and-saving-decimal-values-from-a-form/206983/1 "2011-05-15T06:27:43Z")

</div>

I have an odd bug in one of my applications. When I am using the  
sqlite3 database the bug is not present. However when I use mysql2 as  
the database adapter I run into an error saving decimal values from a  
form. If I submit the value 19.99 my input after the decimal is  
removed and it is stored in the database as 19.00

What would cause this? The database has the correct settings for the  
column and I can create a correct record using the rails console.

---

<div class="post-metadata">

**Author:** ![Devin\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f4b2a3/32.png) [@Devin\_M](https://www.ruby-forum.com/u/Devin_M)\
**Post date:** [May 15, 2011, 9:00am UTC](https://www.ruby-forum.com/t/rails-3-and-saving-decimal-values-from-a-form/206983/2 "2011-05-15T09:00:53Z")

</div>

Sent from my iPhone

On May 14, 2011, at 11:26 PM, Devin M [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have an odd bug in one of my applications. When I am using the  
> sqlite3 database the bug is not present. However when I use mysql2 as  
> the database adapter I run into an error saving decimal values from a  
> form. If I submit the value 19.99 my input after the decimal is  
> removed and it is stored in the database as 19.00
> 
> What would cause this? The database has the correct settings for the  
> column and I can create a correct record using the rails console.

What does your migration file, model and code you are creating the  
record look like? You need to provide something that the group can use  
as a reproducible test case so we can help you.

B.

---

<div class="post-metadata">

**Author:** ![Devin\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f4b2a3/32.png) [@Devin\_M](https://www.ruby-forum.com/u/Devin_M)\
**Post date:** [May 15, 2011, 8:52pm UTC](https://www.ruby-forum.com/t/rails-3-and-saving-decimal-values-from-a-form/206983/3 "2011-05-15T20:52:09Z")

</div>

> What would cause this? The database has the correct settings for the  
> column and I can create a correct record using the rails console.

The only column type that works is “decimal” is that your case?

And gimme a link to your app so that I’ll make it crash by inputting  
decimal values that have a comma 😉

I had to go through this pain for my [http://suivauto.com](http://suivauto.com) website that  
uses the French “,” instead of the “.” for decimal points.

---

<div class="post-metadata">

**Author:** ![Devin\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f4b2a3/32.png) [@Devin\_M](https://www.ruby-forum.com/u/Devin_M)\
**Post date:** [May 15, 2011, 10:40pm UTC](https://www.ruby-forum.com/t/rails-3-and-saving-decimal-values-from-a-form/206983/4 "2011-05-15T22:40:39Z")

</div>

On Sun, May 15, 2011 at 1:52 PM, Fernando P.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> 

To be sure, in your migration you have the precision and scale for the  
column?

t.decimal “amount”, :precision =\> 10, :scale =\> 2
