Jump to content

[SOLVED] Work out a percentage ... but within min or max range


jimbob-2k7

Recommended Posts

Hi All,

 

What I am trying to do is this:

 

1) We start off with a price, we will say £40.

 

2) Then work out what 10% of the price ... so that will be £4.

 

3) That value then must be between a min (£3) and max (£6) value.

 

So £4 will be fine because it's between £3 and £6. But if we start off with £80 (then 10%, so it will be £8) £8 is greater than the max vaule, so set it to the max value.

 

I hope you guys get what I am trying to do.

 

Cheers,

 

Jim

Link to comment
Share on other sites

You want anything lower than £3 to be set to £3?  If you use my code it'll stay as £3... if what you meant was:

 

If it's lower than the min price, set the min price to the new value, do this:

 

<?php

$min = 3;
$max = 6;
$price = 80;

$newPrice = $price/10; // Here's your percentage

if($newPrice > $max) {

$max = $newPrice;

} else if($newPrice < $min) {

$min = $newPrice;

}

?>

 

Voila :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.