Forum: Ruby on Rails rounding up a floating point number to the nearest integer.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
684e18f86e13bc558b5eb0ceaabf6626?d=identicon&s=25 dodgyboz (Guest)
on 2007-07-13 09:59
(Received via mailing list)
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.
9d1f5d2d9de70bd9a934f557dc95a406?d=identicon&s=25 Daniel ----- (liquid)
on 2007-07-13 10:18
(Received via mailing list)
On 7/13/07, dodgyboz <dodgyboz@gmail.com> wrote:
>
> 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
457cf540784a12ba2f30e06565a2c189?d=identicon&s=25 Hugh Sasse (Guest)
on 2007-07-13 10:19
(Received via mailing list)
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
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2007-07-13 13:29
(Received via mailing list)
On Jul 13, 2007, at 4:17 AM, Daniel N wrote:
>
> 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

Make 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@AgileConsultingLLC.com
684e18f86e13bc558b5eb0ceaabf6626?d=identicon&s=25 dodgyboz (Guest)
on 2007-07-15 17:47
(Received via mailing list)
Thanks
This topic is locked and can not be replied to.