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

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

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

On 11/29/06, DAN [email protected] 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

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