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 8888509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:03:49+00:00 2026-06-14T22:03:49+00:00

I have a value that i need to translate to a percentage given a

  • 0

I have a value that i need to translate to a percentage given a certain set of rules.

VALUE=X

Where X can be anything starting from 0

If:

X > 200

the result of my function should be 100 (percent).

If:

X < 200 AND >= 100

the result should be between 100 and 50 (percent).
Example: X=150 would be 75%

If:

X < 100 AND >= 80

the result should be between 50 and 25 (percent).
Example: X=90 would be 37.5%

And if:

X < 80

the result should be between 25 and 0 (percent).

My approach in PHP would be something like

if($value > 200) return 100;
if($value > 100 && $value < 200) return ???;

… and so on.

Wherein ??? obviously stands for the formula i don’t know how to set up.

Is there a way to do this in one single formula?
And even if not – what is the mathematical approach to this problem?

I know it is very basic but it seems i skipped too many maths lessons in primary school.

  • 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-06-14T22:03:52+00:00Added an answer on June 14, 2026 at 10:03 pm

    The function can be defined piecewisely:

    enter image description here

    Graphically, this is represented with four straight lines of different gradients. While there isn’t a way to represent this function without separate pieces, implementing the above is quite easy.

    In PHP, this function can be written as:

    function f($x) {
        if ($x >= 200)
            return 100;
        if ($x >= 100 && $x < 200)
            return 50 + 50 * (($x - 100) / 100);
        if ($x >= 80 && $x < 100)
            return 25 + 25 * (($x - 80) / 20);
        if ($x < 80)
            return 25 * ($x / 80);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bool value that I need to display as Yes or No
I have an XML file consisting of Name/Value pairs that I need in a
Need some help with DataFormatString in GridView. I have a Double value that needs
I have the following jQuery calls chain: $(someSelector).nextUntil(.specialClass).addClass(classBasedSomeSelectorObject) I need to addClass that's value
I have this code that works in FreePascal under Windows and need to translate
I need to be able to replace certain characters so that I can use
I need help with this exercise where I have to translate properties from English
I have values that are 64-bit unsigned ints, and I need to store them
I have a table with string values that need to matched individually to a
I have id values for products that I need store. Right now they are

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.