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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:44:00+00:00 2026-06-04T14:44:00+00:00

I have the following calculation to make: float value = MY_VALUE; float percentage =

  • 0

I have the following calculation to make:

float value = MY_VALUE;

float percentage = (value - MIN)/(MAX - MIN);
if (percentage < 0)
   percentage = 0;
if (percentage > 1)
   percentage = 1

I was just wondering if there is some method that exists in Objective-C or C to help accomplish this, like for example a method that will round the “value” float to be between the MIN and MAX bounds.

  • 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-04T14:44:01+00:00Added an answer on June 4, 2026 at 2:44 pm

    No.

    On another note, you should probably update your code so you are preventing a possible divide-by-zero:

    float den = (value - MIN);
    float num = (MAX - MIN);
    float percentage;
    
    if(den) {
      percentage = num / den;
      if (percentage < 0.0f ) {
        percentage = 0.0f;
      } else if (percentage > 1.0f) {
        percentage = 1.0f;
      } else {
        printf("Percentage: %3.2f",percentage);
      }
    } else {
      percentage = 0.0f;
      printf("DIVIDE BY ZERO ERROR!");
    }
    

    Also, careful. Oracle is suing Google over a very similar piece of code. You may want to reconsider posting it publicly:

    http://developers.slashdot.org/story/12/05/16/1612228/judge-to-oracle-a-high-schooler-could-write-rangecheck

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

Sidebar

Related Questions

I have following JavaScript function to make some calculation with textboxes but when I
I have the following code with a structure array with data to make some
I have created an application that does the following: Make some calculations, write calculated
I have following method in wcf webenabled service Public Person AddPerson(Person p); As of
I have created the following functions in C#: float GetPI() { return 22.0f/7.0f; }
There was some code like this: // Convenience to make things more legible in
I have the following method to convert a duration in seconds to hours. For
In PHP, I have the following code for calculating the distance between two locations:
I have the following text input on a budget calculator form which displays the
I have the following assignment: Write a complete 8086 program to perform the calculator

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.