Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
August 5th, 2013, 08:00 AM
 fxlightning06
Registered User

Join Date: Aug 2013
Posts: 7
Time spent in forums: 1 h 22 m 53 sec
Reputation Power: 0
Giving Percentages to numbers

Hello, I'm new to these forums and decided to join when I heard from a few friends that this was the best forum on the net for programming. I hope to learn a lot from you guys. Now onto the problem.

I was wondering how I would take a previous given number and give it a percentage. For example If I give three numbers and a final number. I want the final number to be 30 percent of the first number, 20 percent of the second number, and 50 percent of the third. How would I do something like that? I am confused at this point because I have never done anything like this before. Any help would be appreciated thanks.

#2
August 5th, 2013, 08:31 AM
 MrFujin
Lord of the Dance

Join Date: Oct 2003
Posts: 3,359
Time spent in forums: 2 Months 2 Weeks 4 Days 22 h 6 m 19 sec
Reputation Power: 1828
Multiply the numbers with respectively 0.3, 0.2 and 0.5 and then add the result together.

If you need more help, you will have to show what you have done/tried. For example, where does the numbers come from?

#3
August 7th, 2013, 01:37 PM
 fxlightning06
Registered User

Join Date: Aug 2013
Posts: 7
Time spent in forums: 1 h 22 m 53 sec
Reputation Power: 0
Quote:
 Originally Posted by MrFujin Multiply the numbers with respectively 0.3, 0.2 and 0.5 and then add the result together. If you need more help, you will have to show what you have done/tried. For example, where does the numbers come from?

This is what I have so far.

var Totalgrade = (HG + RG + FG)

The numbers seem to be much higher than they should be.

#4
August 7th, 2013, 02:21 PM
 Jacques1
You have been warned

Join Date: Jul 2012
Posts: 3,124
Time spent in forums: 2 Months 3 Weeks 5 Days 8 h 6 m 12 sec
Reputation Power: 1063
I think this is more a problem of elementary math (and not reading carefully enough) than it is a programming issue.

75 per cent(!) of Hmwkgrade is 75 hundreds of it. It's not 75 times Hmwkgrade.

I mean, I do wish that an interest rate of 3% would triple the capital each each. But unfortunately, that's not what "per cent" means.

So what you want is

Code:
`Hmwkgrade * 0.75`

MrFujin actually said this in his reply.

#5
August 7th, 2013, 02:23 PM
 fxlightning06
Registered User

Join Date: Aug 2013
Posts: 7
Time spent in forums: 1 h 22 m 53 sec
Reputation Power: 0
Quote:
 Originally Posted by Jacques1 I think this is more a problem of elementary math (and not reading carefully enough) than it is a programming issue. 75 per cent(!) of Hmwkgrade is 75 hundreds of it. It's not 75 times Hmwkgrade. I mean, I do wish that an interest rate of 3% would triple the capital each each. But unfortunately, that's not what "per cent" means. So what you want is Code: `Hmwkgrade * 0.75` MrFujin actually said this in his reply.

Thanks, I made such a stupid mistake, I copied a a particular part of a program I made and didn't adjust it. Thank you for your help.

#6
August 7th, 2013, 02:53 PM
 fxlightning06
Registered User

Join Date: Aug 2013
Posts: 7
Time spent in forums: 1 h 22 m 53 sec
Reputation Power: 0
Quote:
 Originally Posted by MrFujin Multiply the numbers with respectively 0.3, 0.2 and 0.5 and then add the result together. If you need more help, you will have to show what you have done/tried. For example, where does the numbers come from?

How would I be able to give the total grade a letter value, for example A+ >=95 would I need to use an array?

 Viewing: Dev Shed Forums > Web Design > JavaScript Development > Giving Percentages to numbers