# Math Help - How to find the percentage number?

1. ## How to find the percentage number?

Hi all.

I'm trying to find a percentage of a number but getting a lot of weird answers.

I'm learning programming so I'll try and keep it in its format.

gdp = 100
spending = 5 (this is 5%, I want to be able to find how much this percentage is)

How would I do this? I've tried (gdp / spending) * 100 but that gave an answer like 0.0000033666.

2. ## Re: How to find the percentage number?

Can you post the code or part of the code that you've tried because as per your given information I don't think there is a way of getting that weird answer

3. ## Re: How to find the percentage number?

Code:
gdp = 0
spending = 0
gdpinput = int(input("Enter your countries GDP: ")) This lets the user input the country's gdp
spending = int(input("Enter the spending % of gdp (ex. 0.03 for 3%): ")) This asks the user to input the country's spending
budget = (gdpinput / spending) * 100 This was my failed calculation

print(budget)
Sorry if this is confusing, I'm just trying to figure out how to find how much money is in the percentage. Say the user inputs 30% of gdp spending, I'd like to figure out how much that 30% is.

Thanks

EDIT:

I think I've figured it out.

I changed

Code:
budget = (gdpinput / spending) * 100
to this

Code:
budget = (gdpinput * spending) / 100

4. ## Re: How to find the percentage number?

If, say, gdpinput is in dollars, then (gdpinput * spending) is the dollar value of spending. I am not sure how to describe (gdpinput * spending) / 100 other than 1/100th of the dollar value of spending.

If spending is the actual fraction, say, 0.03, then spending * 100 is the same fraction expressed as percents; in this case, 3%. But if x is a dollar value, then x / 100 is in no way the same value.

5. ## Re: How to find the percentage number?

I'm confused, does that mean I'm wrong?

6. ## Re: How to find the percentage number?

Originally Posted by Amalur
I'm confused, does that mean I'm wrong?
Yes if the variable spending contains an actual fraction (not expressed in percents), which is what your code says.

Why don't you make several test input/output values and see if you code works correctly. Say, for your example in post #1 where gdp is 100 and spending is 0.05, what should the budget be?

7. ## Re: How to find the percentage number?

I get 0.05. Isn't that correct? 0.05% of 100 is 0.05 (I hope)

8. ## Re: How to find the percentage number?

Originally Posted by Amalur
0.05% of 100 is 0.05 (I hope)
That is correct. However, it is not clear how you enter 0.05%. Your code asks to enter it as a fraction not expressed in percents, i.e., as 0.0005. In this case, 100 * 0.0005 = 0.05 and no division by 100 is necessary. (This is not to mention that your example from post #1 had spending equal to 5%, or 0.05 and not 0.05%.)

If you enter spending in percents, then budget = gdpinput * spending / 100.
If you enter spending as an actual fraction (not in percents), then budget = gdpinput * spending.