Re: Rounding up to the next .5



Justin C wrote:
I'm writing a utility for work that will calculate the price to send a
parcel. The courier charges by the half kilo and they never round
down.

I'm trying to round weights (with up to two decimal places) up to the
next half kilo (unless the weight is an exact or .5 kilo already).

I think you are making this waaaay to complicated.
For one I am pretty sure there are modules on CPAN that do floor() and
ceiling() functions.
And second there are really only three simple cases that you need to
distinguish:

if the decimal portion is 0 then the shipping weight is the actual weight
If 0 < decimal portion <= 0.5 then the shipping weight is the integer part
plus 0.5
If 0.5 < decimal portion then the shipping weight is the integer part plus 1

jue


.



Relevant Pages

  • Re: US English take on bread
    ... are still imperial is that I Kilo of water weighed = I Litre of water ... for different flours etc surely the above makes metric the measurement ...
    (rec.food.sourdough)
  • Re: The Speed of Light
    ... This prompted a friend of mine to ask me how much weight I'd need to ... My first trip up the mountain took 61 minutes. ... This was 95 kilos + 12 kilos in bike, ... The first time I run the equation I get 103.1 kilo and 44 minutes 18 ...
    (rec.bicycles.misc)
  • Re: Rounding up to the next .5
    ... I'm trying to round weights up to the ... next half kilo (unless the weight is an exact or .5 kilo already). ... If 0.5 < decimal portion then the shipping weight is the integer part plus 1 ...
    (comp.lang.perl.misc)
  • Re: Opinions please: Suzuki Freewind engine "stuttering" (its also a bit dyslexic)
    ... Sucking his keyboard for inspiration, ... than 2bhp per kilo of my weight. ...
    (uk.rec.motorcycles)