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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:49:26+00:00 2026-05-26T08:49:26+00:00

I want to get two ints, one divided by the other to get a

  • 0

I want to get two ints, one divided by the other to get a decimal or percentage.
How can I get a percentage or decimal of these two ints?
(I’m not sure if it is right.. I’m probably way off…)
for example:

int correct = 25;
int questionNum = 100;
float percent = correct/questionNum *100;

This is how I thought I could do it, but it didn’t work… I want to make the decimal (if there is one) into a percent out of 100 for example in this case it is %25. any ideas anyone?

Here is the correct code (thanks to Salvatore Previti!):

float correct = 25;
float questionNum = 100;
float percent = (correct * 100.0f) / questionNum;

(btw, I am making a project using this for a quiz checking program that is why I need the percentage or decimal)

  • 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-26T08:49:27+00:00Added an answer on May 26, 2026 at 8:49 am

    If you don’t add .0f it will be treated like it is an integer, and an integer division is a lot different from a floating point division indeed 🙂

    float percent = (n * 100.0f) / v;
    

    If you need an integer out of this you can of course cast the float or the double again in integer.

    int percent = (int)((n * 100.0f) / v);
    

    If you know your n value is less than 21474836 (that is (2 ^ 31 / 100)), you can do all using integer operations.

    int percent = (n * 100) / v;
    

    If you get NaN is because wathever you do you cannot divide for zero of course… it doesn’t make sense.

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

Sidebar

Related Questions

I have the following two queries which I want to get in one query.
I'm trying to get two Divs to sit side by side. I want one
I want to get the difference between two sets of ints in c#. Given
I want to get data from two tables. I have patient first name and
I want to get data from two tables with single Entity class. How?? public
I want to get the single digits from two digits.for example if 36 I
I want to get aspect ratio of a monitor as two digits : width
I have two employee lists that I want to get only unique records from
Using Access 2003 I want to get a table value from the two databases
I want to do a functional like pattern match to get the first two

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.