Re: Rounding up to the next .5
- From: "Jürgen Exner" <jurgenex@xxxxxxxxxxx>
- Date: Sat, 28 Apr 2007 16:34:40 GMT
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
.
- Follow-Ups:
- Re: Rounding up to the next .5
- From: Justin C
- Re: Rounding up to the next .5
- References:
- Rounding up to the next .5
- From: Justin C
- Rounding up to the next .5
- Prev by Date: Re: perl newbie
- Next by Date: Re: Memory Management
- Previous by thread: Rounding up to the next .5
- Next by thread: Re: Rounding up to the next .5
- Index(es):
Relevant Pages
|
|