Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# A divided by B displays C percent

Posted on 2007-10-15
Medium Priority
845 Views
Assuming you have two variables...

How would I display to screen a number representing a percentage?  In other words, if correctAnswersCount = 12 and questionsAnswer = 24, then I want to have a number displayed like this:  50%

I also need the result round to the nearest integer.  IOW, a result of 50.7 should be displayed as 51%

0
Question by:Monroe406
• 5

LVL 11

Expert Comment

ID: 20079616
0

LVL 11

Expert Comment

ID: 20079621
or

0

LVL 11

Accepted Solution

Isisagate earned 200 total points
ID: 20079629

Forgot the percent signs
0

Author Comment

ID: 20080085
Whoops!  I awarded the answer to quickly.  Your solution below fails to deal with the nearest integer part of my question.  Your answer will end up displaying unsightly decimal portions:   66.666666666666 %  instead of 67 %
0

LVL 11

Expert Comment

ID: 20080288
Math.round(correctAnswersCount/questionsAnswered)*100) will round up if past .5 and down if below...

Math.ceil will round up if it's larger then a whole number
Math.floor will round down if less then a whole number..

use which ever work for you
0

LVL 11

Expert Comment

ID: 20080292

forgot a ( in that snippet....
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
###### Suggested Courses
Course of the Month12 days, 11 hours left to enroll

#### 578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.