dodgyboz
2007-Jul-13 07:58 UTC
rounding up a floating point number to the nearest integer.
I need to round up a floating point number to the nearest integer. So 2.3 would become 3 instead of 2 which is what happens if i use 2.3.round. does anyone know of a simple way to do this? if not could you please point my in the right direction for a more complicated way. Thank you. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Daniel N
2007-Jul-13 08:17 UTC
Re: rounding up a floating point number to the nearest integer.
On 7/13/07, dodgyboz <dodgyboz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I need to round up a floating point number to the nearest integer. So > 2.3 would become 3 instead of 2 which is what happens if i use > 2.3.round. > > does anyone know of a simple way to do this? > > if not could you please point my in the right direction for a more > complicated way. > > Thank you.Round will round to the nearest integer. This is not always down. The builtin method :ceil is the one your after here. 2.3.ceil #=> 3 Cheers Daniel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hugh Sasse
2007-Jul-13 08:18 UTC
Re: rounding up a floating point number to the nearest integer.Z
On Fri, 13 Jul 2007, dodgyboz wrote:> > I need to round up a floating point number to the nearest integer. So > 2.3 would become 3 instead of 2 which is what happens if i use > 2.3.round. > > does anyone know of a simple way to do this?brains hgs 31 %> irb irb(main):001:0> 2.3.ceil => 3 irb(main):002:0> quit brains hgs 32 %> Hugh --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2007-Jul-13 11:28 UTC
Re: rounding up a floating point number to the nearest integer.
On Jul 13, 2007, at 4:17 AM, Daniel N wrote:> On 7/13/07, dodgyboz <dodgyboz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I need to round up a floating point number to the nearest integer. So > 2.3 would become 3 instead of 2 which is what happens if i use > 2.3.round. > > does anyone know of a simple way to do this? > > if not could you please point my in the right direction for a more > complicated way. > > Thank you. > > Round will round to the nearest integer. This is not always down. > The builtin method :ceil is the one your after here. > > 2.3.ceil #=> 3 > > Cheers > DanielMake sure that, if you have negative values, that you understand that "up" means "toward positive Infinity" -2.3.ceil #=> -2 -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dodgyboz
2007-Jul-15 15:47 UTC
Re: rounding up a floating point number to the nearest integer.
Thanks On Jul 13, 10:17 am, "Daniel N" <has....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 7/13/07, dodgyboz <dodgy...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I need to round up a floating point number to the nearest integer. So > > 2.3 would become 3 instead of 2 which is what happens if i use > > 2.3.round. > > > does anyone know of a simple way to do this? > > > if not could you please point my in the right direction for a more > > complicated way. > > > Thank you. > > Round will round to the nearest integer. This is not always down. The > builtin method :ceil is the one your after here. > > 2.3.ceil #=> 3 > > Cheers > Daniel--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---