From: Dermot Moynihan Date: 2006-12-27T00:50:03+09:00 Subject: Re: Newby - how to round up floating point number? Thanks Jeroen. Been doing a bit of reading on 'ceil' and 'floor' and am wondering if you have to know the actual number you are going to be working on in order to use them. Because I don't know what that number will be. Did you skim read that post - I gave some examples to try to make that point. Or have I just misunderstood how to use 'ceil' or 'floor'. I would have thought this would be a fairly mundane task. After all if one wants 1 and a bit ice creams or whatever, he must get two not one. So, rounding up is surely pretty important. Been experimenting with a thing called 'round' but that rounds up if the figure after the decimal point is .5 or greater, otherwise it rounds down. But I need it always UP if there is greater than zero after the decimal. Just to sum up again: what I'm looking for is a way of always rounding up a floating point number that arrives after some calculations. The answer will vary as a result of the figures used in the calculation varying. e.g. if the final number is 6.1234 I want it rounded up to 7. If the final number is 23.025875 I want it rounded up to 24. However, if 17.0 then have it stay 17. Or if 21.0 stay 21. And so on. I suppose what I need is some way of saying: IF the answer is a floating point decimal number round it up. If there is nothing after the decimal point (e.g. 46.0) leave it alone (46). Thanks for your help. Dermot Jeroen Budts wrote: > On 2006-12-26 14:00, Dermot Moynihan wrote: >>> Let's say that after a calculation I get 4.1200056 and I want to round >>> it up to 5. >>> When the calculation comes to a number like 4.0 I want it left at 4. > > Hi! > > You can use the 'ceil'-method: > > (4.1).ceil # => 5 > (4.7).ceil # => 5 > (4.0).ceil # => 4 > > fyi: there is also the floor method which always returns the lower number: > (4.1).floor # => 4 > (4.7).floor # => 4 > (4.0).floor # => 4 > > > greetz! > Jeroen