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

  • SEARCH
  • Home
  • 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 6655625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:32:34+00:00 2026-05-26T01:32:34+00:00

How can I find the formula that would, based on a percentage value, give

  • 0

How can I find the formula that would, based on a percentage value, give me left and width values based on the following 0% and 100% values?

For 0,00 percentage, left and with values would be:

  • Width: 658
  • Left: 11

For 100,00 percentage, left and width values would be:

  • Width: 0 (or 1)
  • Left: 670

I have a gradient image, on which I apply a color to give the percentage value a visual representation.
The gradient image starts at 11 pixels (Left: 11 for 0,00%) and has a width of 659 (Left: 670 for 100,00% = 659 + 11)

The left and width values needs to be calculate dynamically based on the percentage so that the color overlays the gradient.

If the percentage is 0%, the color would overlay the whole gradient (left: 11, width: 659)

------------------------------
|____________________________|
0                            100

If the percentage is 100%, the color would not overlay the gradient at all (left: 670 which is 659 + 11, width: 1 or 0)

                              -
|____________________________|
0                            100
  • 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-26T01:32:34+00:00Added an answer on May 26, 2026 at 1:32 am

    The formula you’re looking for can be expressed as f(x) = ax+b. f(x) is the width you want to get, x is the percentage, and a & b are (currently unknown) constants.

    If you have the value of f(x) for two points (0 and 100 for instance), you can derive the formula like so:

    f(0) = valueAtZero = a*0 + b
    b = valueAtZero
    f(100) = valueAtOneHundred = a*100 + b
    valueAtOneHundred - b = a*100
    a = (valueAtOneHundred - b) / 100
    

    Now that you have a and b, you can solve for any percentage x you want. The process above translates into pseudocode as:

    function getValueAtXPercent(x, valueAtZero, valueAtOneHundred):
        b = valueAtZero
        a = (valueAtOneHundred - b) / 100
        return a*x + b
    

    now you can call getValueAtXPercent(50, 658, 1) and it will return your width value for 50%.

    Here is a concrete implementation, in python:

    def f(x, valueAtZero, valueAtOneHundred):
        b = valueAtZero
        a = (valueAtOneHundred - b) / 100.0
        return a*x + b
    
    def showStats(percent):
        left = f(percent, 11, 670)
        width = f(percent, 658, 0)
        output = "At {0}%, left={1} and width={2}".format(percent, left, width)
        print output
    
    showStats(0)
    showStats(50)
    showStats(100)
    

    output:

    At 0%, left=11.0 and width=658.0
    At 50%, left=340.5 and width=329.0
    At 100%, left=670.0 and width=0.0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've searched for an answer, but it seems that I can only find VBA-based
I want to find a combinatorial formula that given a certain number of integers,
Can I somehow find out what was the change in the textfield? I would
I have a mathematical formula in my program that takes in two values, both
I can find tutorials about mapping textures to polygons specifying vertices etc. but nothing
I can find lots of information on how Long Polling works (For example, this
I can find a direct table foreign key in c# like: foreach (ForeignKey key
How can find max of three numbers in XSL ? More Information : I
Where can find resources about best practices for SharePoint programming? I am talking about
I can find no non-deprecated way of hiding an item in a menu bar

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.