From: Dermot Moynihan Date: 2007-01-07T07:24:35+09:00 Subject: Re: Newby - how to round up floating point number? Thanks bbiker. Also, further thanks to Gaurav and Phrogz, for supplying additional very welcome pointers. Problem sorted and put to bed. All the very best Dermot bbiker wrote: > Dermot Moynihan wrote: >> Thanks Jeroen. >> >> 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 >> > To me it appears that what you wan is ceil ... it alway rounds up > 1.000000001.ceil => 2 > 1.0.ceil => 1 > > To round down, use floor > 1.99999999.floor => 1 > 2.0.floor => 2 > > there's also round ... which rounds up if the fractional part is >= > 0.5 otherwise rounds down > 2.5.round => 3 > 2.49999999.round => 2 > > note that ceil, floor, and round have no effect on integer > > 5.ceil => 5 5.floor => 5, 5.round => 5 > > pick the method whose behavior you want > > >