Re: Rounding up to the next .5



In article <AIKYh.2898$r77.978@trndny08>, Jürgen Exner wrote:
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.

Sometimes you're too busy following logic to see the lateral.


For one I am pretty sure there are modules on CPAN that do floor() and
ceiling() functions.

There are that, and, IIRC (from today's Googling for a round() function)
they are part of POSIX, and therefore (if my understanding is correct)
already installed.

Trouble is, I don't know what those are/do, perldoc wasn't much help,
I suppose they're mathematical functions, I didn't get that far with my
education and so didn't understand, and perldoc -q round, though it
mentioned those, didn't explain them in a way I'd understand that they
are relevant to my problem.


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

Now that's a lateral solution to the problem. I'm pretty sure I can
manage that too!

J?rgen, thank you for your help.

Justin.

--
Justin C, by the sea.
.



Relevant Pages

  • Re: A Brief history of overweight, out-of-shape players...
    ... There's no such thing as a person who cant control their weight. ... Do you remember Darnell Alford an OL from Boston College? ... round ability but was drafted in the 6th round in 2000. ... became the first 400-pound player and he has had an undistinguished ...
    (alt.sports.football.pro.ne-patriots)
  • Re: armament change
    ... The trade offs are a more lethal round, so less needed to hit, versus ... were not) the weight of gun and weight of shot is proportional to the ... US 0.30 inch M2 Browning machine gun, weight 23 pounds, weight ... of six 0.50 calibre machine guns, but could carry only about 1/3 the ...
    (rec.aviation.military)
  • Re: armament change
    ... The trade offs are a more lethal round, so less needed to hit, versus ... were not) the weight of gun and weight of shot is proportional to the ... US 0.30 inch M2 Browning machine gun, weight 23 pounds, weight ... of six 0.50 calibre machine guns, but could carry only about 1/3 the ...
    (rec.aviation.military)
  • Re: Alcohol Drying of Wet Wood
    ... Fred Holder wrote: ... The piece has lost 58 percent of its original weight in ten ... It was out of round by less that 1/16 inch. ... After the last discussion on alcohol, ...
    (rec.crafts.woodturning)
  • Re: Swing Videos - Critiques Please
    ... Kick the right knee in and keep the weight on the inside of the right ... Ford and had the best round of my life. ... foot kept my backswing length in check and got me to the front foot ...
    (rec.sport.golf)