We''re developing a system that''s used for tracking company IPO
data
and we''re running into a few number storage issues. For large numbers,
i.e. numbers greater than 100 million, MySQL insists on storing these
as scientific notation. I don''t really have a problem with that but
when we want to edit these fields using something like:
<% form_for(@company) do |f| %>
<p>
<%= f.text_field :some_large_number_field , :size => 20 %>
<%= f.submit "Update" %>
</p>
<% end %>
the field is presented to the user with the number in scientific
notation form, not what we want unfortunatly, since the users won''t
understand this. We''ve looked at a bunch of documentation but can only
find info on getting numbers into scientific notation, not the other
way around.
Is there a way to either force MySQL to store the numbers normally or
have them formatted on the way out?
Dale
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Why not just store the number as a String and convert it to a number in Ruby? Chris On Mon, Apr 14, 2008 at 4:46 PM, PeteSalty <petesalty-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > We''re developing a system that''s used for tracking company IPO data > and we''re running into a few number storage issues. For large numbers, > i.e. numbers greater than 100 million, MySQL insists on storing these > as scientific notation.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> We''re developing a system that''s used for tracking company IPO data > and we''re running into a few number storage issues. For large numbers, > i.e. numbers greater than 100 million, MySQL insists on storing these > as scientific notation.What''s wrong with DECIMAL date type? mysql> create table t(n decimal(12,2)); Query OK, 0 rows affected (0.04 sec) mysql> insert into t values(1234567890.11); Query OK, 1 row affected (0.01 sec) mysql> select * from t; +---------------+ | n | +---------------+ | 1234567890.11 | +---------------+ 1 row in set (0.00 sec) Regards, -- Rimantas http://rimantas.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 -~----------~----~----~----~------~----~------~--~---
100 Million isn''t that large, certainly not for a float. There are so many issues with doing it this way I don''t know where to start. Thanks for the suggestion though. On Apr 14, 4:10 pm, "Chris Johnston" <fuzzyliz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Why not just store the number as a String and convert it to a number in > Ruby? > > Chris > > On Mon, Apr 14, 2008 at 4:46 PM, PeteSalty <petesa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > We''re developing a system that''s used for tracking company IPO data > > and we''re running into a few number storage issues. For large numbers, > > i.e. numbers greater than 100 million, MySQL insists on storing these > > as scientific notation.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Because decimals have fixed decimal places, which just doesn''t work with this kind of financial data - not all numbers are going to be dollar and cent amounts. On Apr 14, 4:15 pm, "Rimantas Liubertas" <riman...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > We''re developing a system that''s used for tracking company IPO data > > and we''re running into a few number storage issues. For large numbers, > > i.e. numbers greater than 100 million, MySQL insists on storing these > > as scientific notation. > > What''s wrong with DECIMAL date type? > > mysql> create table t(n decimal(12,2)); > Query OK, 0 rows affected (0.04 sec) > > mysql> insert into t values(1234567890.11); > Query OK, 1 row affected (0.01 sec) > > mysql> select * from t; > +---------------+ > | n | > +---------------+ > | 1234567890.11 | > +---------------+ > 1 row in set (0.00 sec) > > Regards, > -- > Rimantashttp://rimantas.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 -~----------~----~----~----~------~----~------~--~---
Let me clarify this question. I''m not looking for other storage types, I''m looking for an answer as to 1. Why MySQL would be forcing some of the large numbers into scientific notation and if there''s a way to stop it from doing that. 2. Baring that, is there a simple way to force the formatting back into standard notation for editing? Thanks Dale On Apr 14, 3:46 pm, PeteSalty <petesa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> We''re developing a system that''s used for tracking company IPO data > and we''re running into a few number storage issues. For large numbers, > i.e. numbers greater than 100 million, MySQL insists on storing these > as scientific notation. I don''t really have a problem with that but > when we want to edit these fields using something like: > > <% form_for(@company) do |f| %> > <p> > <%= f.text_field :some_large_number_field , :size => 20 %> > <%= f.submit "Update" %> > </p> > <% end %> > > the field is presented to the user with the number in scientific > notation form, not what we want unfortunatly, since the users won''t > understand this. We''ve looked at a bunch of documentation but can only > find info on getting numbers into scientific notation, not the other > way around. > Is there a way to either force MySQL to store the numbers normally or > have them formatted on the way out? > > Dale--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
To clarify this even further. Can you let us know what kind of object you are using to store the value in Ruby and what type you are using for the row in MySQL? On Mon, Apr 14, 2008 at 8:52 PM, PeteSalty <petesalty-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Let me clarify this question. I''m not looking for other storage types, > I''m looking for an answer as to > > 1. Why MySQL would be forcing some of the large numbers into > scientific notation and if there''s a way to stop it from doing that. > 2. Baring that, is there a simple way to force the formatting back > into standard notation for editing? > > Thanks > Dale > > On Apr 14, 3:46 pm, PeteSalty <petesa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > We''re developing a system that''s used for tracking company IPO data > > and we''re running into a few number storage issues. For large numbers, > > i.e. numbers greater than 100 million, MySQL insists on storing these > > as scientific notation. I don''t really have a problem with that but > > when we want to edit these fields using something like: > > > > <% form_for(@company) do |f| %> > > <p> > > <%= f.text_field :some_large_number_field , :size => 20 %> > > <%= f.submit "Update" %> > > </p> > > <% end %> > > > > the field is presented to the user with the number in scientific > > notation form, not what we want unfortunatly, since the users won''t > > understand this. We''ve looked at a bunch of documentation but can only > > find info on getting numbers into scientific notation, not the other > > way around. > > Is there a way to either force MySQL to store the numbers normally or > > have them formatted on the way out? > > > > Dale > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Because decimals have fixed decimal places, which just doesn''t work > with this kind of financial data - not all numbers are going to be > dollar and cent amounts.Well it shouldn''t be dollar and cents, you can define how many decimal places you want. Other types will give you more rounding errors, is that good for financial data? Regards, Rimantas -- http://rimantas.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 -~----------~----~----~----~------~----~------~--~---
If it''s money you are talking about, use the Money gem. It takes care of lots of the syntax and conversion and accuracy for you. It actually stores the values as very large integers (i.e. cents). http://dist.leetsoft.com/api/money/ -Danimal On Apr 14, 4:46 pm, PeteSalty <petesa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> We''re developing a system that''s used for tracking company IPO data > and we''re running into a few number storage issues. For large numbers, > i.e. numbers greater than 100 million, MySQL insists on storing these > as scientific notation. I don''t really have a problem with that but > when we want to edit these fields using something like: > > <% form_for(@company) do |f| %> > <p> > <%= f.text_field :some_large_number_field , :size => 20 %> > <%= f.submit "Update" %> > </p> > <% end %> > > the field is presented to the user with the number in scientific > notation form, not what we want unfortunatly, since the users won''t > understand this. We''ve looked at a bunch of documentation but can only > find info on getting numbers into scientific notation, not the other > way around. > Is there a way to either force MySQL to store the numbers normally or > have them formatted on the way out? > > Dale--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I don''t know how to attack MySQL. Sorry. When you pull the info from the database, does @number.to_f give you scientific still? -Kyle On Apr 15, 10:28 am, Danimal <fightonfightw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> If it''s money you are talking about, use the Money gem. It takes care > of lots of the syntax and conversion and accuracy for you. It actually > stores the values as very large integers (i.e. cents). > > http://dist.leetsoft.com/api/money/ > > -Danimal > > On Apr 14, 4:46 pm, PeteSalty <petesa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > We''re developing a system that''s used for tracking company IPO data > > and we''re running into a few number storage issues. For large numbers, > > i.e. numbers greater than 100 million, MySQL insists on storing these > > as scientific notation. I don''t really have a problem with that but > > when we want to edit these fields using something like: > > > <% form_for(@company) do |f| %> > > <p> > > <%= f.text_field :some_large_number_field , :size => 20 %> > > <%= f.submit "Update" %> > > </p> > > <% end %> > > > the field is presented to the user with the number in scientific > > notation form, not what we want unfortunatly, since the users won''t > > understand this. We''ve looked at a bunch of documentation but can only > > find info on getting numbers into scientific notation, not the other > > way around. > > Is there a way to either force MySQL to store the numbers normally or > > have them formatted on the way out? > > > Dale--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---