Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7569803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:15:28+00:00 2026-05-30T15:15:28+00:00

I am trying to find whether a variable that I am calculating falls within

  • 0

I am trying to find whether a variable that I am calculating falls within a 20% range of a predefined number.

For example: predefined number is 8 (20% is 1.6) so the number would need to fall between 6.4 and 9.6.

What would be the best way to do this via PHP please?

//——————- APOLOGIES FOUND A WORKING ANSWER

Apologies worked this out by thinking about it!

Here is the code for others:

// Calculating the variables and defining the top and bottom ($read = 8 for example)
$calspeed = $read * 0.2;
$topspeed = $read + $calspeed;
$btmspeed = $read - $calspeed;

// $avg is taken from a sql query drawn from database
if ($avg > $btmspeed && $avg < $topspeed){
    echo "this is an acceptable reading speed";
}else{
    echo "wrong";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:15:29+00:00Added an answer on May 30, 2026 at 3:15 pm
    <?PHP
    $predefined = <<WHATEVER>>;
    $range = (float) $predefined * 0.2;
    if ( $range > abs( (float)$input - (float)$predefined))) {
      //Declare Victory
    }
    

    This has the benefit of supporting integers and allows you to coerce the values into something similar for the more complicated data formats.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find the PayPal IPN HTML variables that I would need to
I am using UICatalog example and trying to find whether it is possible to
I am trying to find the fastest way to check whether a given number
To find whether N is a prime number we only need to look for
I am trying to find whether number is prime or not for 1000 digit
I trying to find whether the elements of 2 arrayLists are match or not.
I'm trying to find out whether I should be using business critical logic in
I'm trying to find out whether a Socket is currently connected - according to
What I'm trying to find out is whether there is some sort of equivalence
I'm trying to find a Git Commit Monitor for Windows. Does anyone know whether

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.