Rails 3.1.3 I have a field of type, t.decimal "startp", :precision => 4, :scale => 1 which is of course, 13.2, 44.5, 123.9, and so on. Once in a while, some of the values, which are either already stored in DB or newly created, become something like, 9.80000000000000001 or 65.40000000000000000001 which was supposed to be 9.8 and 65.4 respectively (I did not count the number of zeros precisely). It does not happen all the time, it just does once in a while, and I am not sure what''s causing it. Could anyone guess the cause of this issue? soichi -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 19 March 2012 00:41, Soichi Ishida <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Rails 3.1.3 > > I have a field of type, > > t.decimal "startp", :precision => 4, :scale => 1 > > > which is of course, 13.2, 44.5, 123.9, and so on. > > Once in a while, some of the values, which are either already stored in > DB or newly created, become something like, > > > 9.80000000000000001 or 65.40000000000000000001 > > which was supposed to be 9.8 and 65.4 respectively (I did not count the > number of zeros precisely). > > It does not happen all the time, it just does once in a while, and I am > not sure what''s causing it. > > Could anyone guess the cause of this issue?It may be to do with how you are displaying the value that is causing it to be converted to a float before being displayed. How are you displaying the value in order to see it like that? Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Mar 19, 2012 at 9:05 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 19 March 2012 00:41, Soichi Ishida <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Rails 3.1.3 >> >> I have a field of type, >> >> t.decimal "startp", :precision => 4, :scale => 1 >> >> >> which is of course, 13.2, 44.5, 123.9, and so on. >> >> Once in a while, some of the values, which are either already stored in >> DB or newly created, become something like, >> >> >> 9.80000000000000001 or 65.40000000000000000001 >> >> which was supposed to be 9.8 and 65.4 respectively (I did not count the >> number of zeros precisely). >> >> It does not happen all the time, it just does once in a while, and I am >> not sure what''s causing it. >> >> Could anyone guess the cause of this issue? > > It may be to do with how you are displaying the value that is causing > it to be converted to a float before being displayed. How are you > displaying the value in order to see it like that?It may also have to do with the way the value is assigned to the ActiveRecord setter method. suppose you had a class "Race" with startp as one of the decimal column, then this race.startp = 9.8 will first make a Float 9.8 and then assign that Float to the BigDecimal value. You may try: race.startp = "9.8" # you could use the user supplied string race.startp = BigDecimal.new("9.8") HTH, peter -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.