Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add value to a number by intervals

Status
Not open for further replies.

ability1

Programmer
Dec 24, 2002
23
0
0
US
I have a shopping cart that spits out an end shopping value lets call it $grand_total

what I want is if $grand_total is less than 500 shipping (lets call it $shipping)is 39.95 and shipping should increase by $10 per $100 that grand_total increases.

obviously I could write this to infinity

if ( $grand_total < 400.01 ) {
$shipping= &quot;39.95&quot;;}
elsif ( $grand_total < 500.01 ) {
$shipping= &quot;49.95&quot;;}

but I'm looking for a dynamic approach.

I'm guessing my $i =
$i++; would be where you start but i'm not sure
 
Something like this?
Code:
my $tot = 499;
my $ship = 49.95;

$ship += (int(($tot - 500) / 100) + 1) *10 if($tot > 500);
It checks if total is over 500, then for every $100 over, it adds 10 to the base shipping.

----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
I think you're being too generalised here;

Somethings are small and costs LOTSA
Somethings are HUGE and cost SFA

A percentage weight on shipping is going to drive your custom aweigh (heh, heh, no really)

I persoanlly think you need to look at an additional field in your calculations

HTH
--Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top