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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeff Pritchard
2006-Nov-30 02:16 UTC
Re: How do I convert "1e+06" to "1,000,000" in RoR edit view
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, > DANCan 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Isak Hansen
2006-Nov-30 13:19 UTC
Re: How do I convert "1e+06" to "1,000,000" in RoR edit view?
On 11/29/06, DAN <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 valueSuggest 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> aspect. > > Any links to more info or tutorials appreciated. > > Thanks, > DAN > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---