# How do I convert "1e+06" to "1,000,000" in RoR edit view?

**URL:** <https://www.ruby-forum.com/t/how-do-i-convert-1e-06-to-1-000-000-in-ror-edit-view/77718>\
**Category:** Rails\
**Created:** [November 29, 2006, 10:52pm UTC](https://www.ruby-forum.com/t/how-do-i-convert-1e-06-to-1-000-000-in-ror-edit-view/77718 "2006-11-29T22:52:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [November 29, 2006, 10:52pm UTC](https://www.ruby-forum.com/t/how-do-i-convert-1e-06-to-1-000-000-in-ror-edit-view/77718/1 "2006-11-29T22:52:59Z")

</div>

When I enter “1000000” into my RoR new form it shows up as “1e+06” in a  
mysql float field.

Maybe this is a mysql question, but is there a way to get this to appear  
as “1000000” in my RoR edit form field? It translates fine in the RoR  
show view but not the edit view.

I’m actually using this as currency value also so want to keep the float  
aspect.

Any links to more info or tutorials appreciated.

Thanks,  
DAN

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [November 30, 2006, 3:16am UTC](https://www.ruby-forum.com/t/how-do-i-convert-1e-06-to-1-000-000-in-ror-edit-view/77718/2 "2006-11-30T03:16:49Z")

</div>

DAN wrote:

> When I enter “1000000” into my RoR new form it shows up as “1e+06” in a  
> mysql float field.
> 
> Maybe this is a mysql question, but is there a way to get this to appear  
> as “1000000” in my RoR edit form field? It translates fine in the RoR  
> show view but not the edit view.
> 
> I’m actually using this as currency value also so want to keep the float  
> aspect.
> 
> Any links to more info or tutorials appreciated.
> 
> Thanks,  
> DAN

Can you show us the code in your view for the edit page? You probably  
just need to sneak a “number\_to\_currency” in there in just the right  
place.

from the rdoc…  
number\_to\_currency(number, options = {})  
Formats a number into a currency string. The options hash can be used to  
customize the format of the output. The number can contain a level of  
precision using the precision key; default is 2 The currency type can be  
set using the unit key; default is “$” The unit separator can be set  
using the separator key; default is “.” The delimiter can be set using  
the delimiter key; default is “,”

jp

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [November 30, 2006, 2:21pm UTC](https://www.ruby-forum.com/t/how-do-i-convert-1e-06-to-1-000-000-in-ror-edit-view/77718/3 "2006-11-30T14:21:49Z")

</div>

On 11/29/06, DAN [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> When I enter “1000000” into my RoR new form it shows up as “1e+06” in a  
> mysql float field.
> 
> Maybe this is a mysql question, but is there a way to get this to appear  
> as “1000000” in my RoR edit form field? It translates fine in the RoR  
> show view but not the edit view.
> 
> I’m actually using this as currency value

Suggest you use the decimal/numeric type then. Floating point numbers  
aren’t accurate, and you I’m sure you don’t want rounding errors in  
your books.

Note that you’ll have to update to rails 1.2 for proper decimal support.

There’s also Kernel#sprintf if all you care about is formatting your  
floats.

Isak

also so want to keep the float

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [November 30, 2006, 4:57pm UTC](https://www.ruby-forum.com/t/how-do-i-convert-1e-06-to-1-000-000-in-ror-edit-view/77718/4 "2006-11-30T16:57:15Z")

</div>

Here’s the code I use in the form…

\<%= text\_field ‘invoice’, ‘total\_due’, :size =\> 14 %\>

If I enter “1000000” in the text\_field and submit it then “1e+06” shows  
up in the field when I go to the edit view. Not sure how or why “1e+06”  
is being converted to. I bet it’s in mysql but it could be passed in  
that way from RoR as well I guess. It’s one of those idiosyncrasies that  
I could spend days on trying to figure out.

I’m still pretty new at this and not sure if perhaps there’s some way to  
apply currency format or Kernel#sprintf to the form field. At first  
review it doesn’t seem proper but maybe I’m not seeing the obvious.

Thanks for any help.

DAN
