Re: Rounding up to the next .5
- From: Justin C <justin.0704@xxxxxxxxxxxxxx>
- Date: Sat, 28 Apr 2007 20:36:18 -0000
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.
.
- Follow-Ups:
- Re: Rounding up to the next .5
- From: Tad McClellan
- Re: Rounding up to the next .5
- References:
- Rounding up to the next .5
- From: Justin C
- Re: Rounding up to the next .5
- From: Jürgen Exner
- Rounding up to the next .5
- Prev by Date: Problem with Image::Info
- Next by Date: Re: Problem with Image::Info
- Previous by thread: Re: Rounding up to the next .5
- Next by thread: Re: Rounding up to the next .5
- Index(es):
Relevant Pages
|