for example: i = 0.33533333333 round up to "0.34" thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
david wrote:> i = 0.33533333333 round up to "0.34"sprintf("%2.2f", i) -- Michael Wang --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Tue, 2007-01-16 at 03:54 -0800, Michael Wang wrote:> david wrote: > > i = 0.33533333333 round up to "0.34" > > sprintf("%2.2f", i) >Hmm and if you want a float then: eval(sprintf("%2.2f",i)) Also, if you want to just round: i.round #=> will give 0 for 0.33335 And If you don''t really like eval then, you would have to get your hand dirty and : class Float def round2f places sprintf("%.#{places}f",self).to_f end end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hi, what about this..... irb(main):035:0> i = 0.33533333333 => 0.33533333333 irb(main):036:0> Integer(i*100)/100.0 => 0.33 in case .34 is required can do irb(main):040:0> Integer((i*100).ceil) => 34 regards gaurav On 1/16/07, Hemant Kumar <gethemant-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Tue, 2007-01-16 at 03:54 -0800, Michael Wang wrote: > > david wrote: > > > i = 0.33533333333 round up to "0.34" > > > > sprintf("%2.2f", i) > > > > Hmm and if you want a float then: > > eval(sprintf("%2.2f",i)) > > Also, if you want to just round: > > i.round #=> will give 0 for 0.33335 > > And If you don''t really like eval then, you would have to get your hand > dirty and : > > class Float > def round2f places > sprintf("%.#{places}f",self).to_f > end > end > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi, I''ve got it. thanks, everyone. On 1 16 , 10 53 , "gaurav bagga" <gaurav.v.ba...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi, > what about this..... > > irb(main):035:0> i = 0.33533333333 > => 0.33533333333 > irb(main):036:0> Integer(i*100)/100.0 > => 0.33 > > in case .34 is required > can do > irb(main):040:0> Integer((i*100).ceil) > => 34 > > regards > gaurav > On 1/16/07, Hemant Kumar <gethem...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Tue, 2007-01-16 at 03:54 -0800, Michael Wang wrote: > > > david wrote: > > > > i = 0.33533333333 round up to "0.34" > > > > sprintf("%2.2f", i) > > > Hmm and if you want a float then: > > > eval(sprintf("%2.2f",i)) > > > Also, if you want to just round: > > > i.round #=> will give 0 for 0.33335 > > > And If you don''t really like eval then, you would have to get your hand > > dirty and : > > > class Float > > def round2f places > > sprintf("%.#{places}f",self).to_f > > end > > end--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---