Blitz maths question...
Blitz3D Forums/Blitz3D Beginners Area/Blitz maths question...
| ||
Not sure if this is the right place to post this: but i need to somehow find out how much percentage of somthing is being taken up... like for example: Const Used = 25, Max = 100 then store the amount of percentage is being used in another ver. like (the problem): Percentage_Being_used = Some+math-Used*to/get+the+percentage am i having a brain fart and missing somthing plain in sight? also, the percentage can be more then 100: Const Used = 250, Max = 1000 would still return 25 percent used. |
| ||
(current / max) * 100 |
| ||
that works :D thanks |
| ||
hmm, it did seem to work... but look at this example:Print 200000/500000 * 100 WaitKey() prints 0... ? |
| ||
could it be that those numbers are integers, not floating points? |
| ||
Yup.Print Int(Float(200000)/500000 * 100) WaitKey() EDIT: Note that you can force a floating point result in division by making just one of the numbers floating point. Almost useless trivia, I'm sure, but there you go. |
| ||
You can also do this: (Current*100)/Max Print (200000*100)/500000 That way you don't have to worry about FP inaccuracies if all you need is the integer result. |
| ||
Thanks guys. |
| ||
This is another stupid question, and i'm sure your going to laugh.. How do i get a number by percentage... like i want to retrieve the number 25... like somthing like this: Print "grabbing 25 percent of 1000.." Print GrabNumberPercent(25,1000);Should Return 250. waitkey() Function GrabNumberPercent(Percentage,Number) Return Some+Math+with+Percentage-and*Number End Function |
| ||
Print "25 percent of 1000" Print Percentage(25,1000) WaitKey End Function Percentage(percentage,number) Return percentage*number/100 End Function |
| ||
Thanks! |
| ||
There is a little formula that I learned in the 5th grade that has helped when figuring out percentages, as well as other fractions. Assuming A/B = C/D The numerator of the left fraction multiplied by the denominator of the right fraction will always equal the numerator of the right fraction multiplied by the denominator of the left. So if any value is missing, it can be calculated with the other three. In other words: A*D = B*C A = (B*C)/D B = (A*D)/C C = (A*D)/B D = (B*C)/A So if you want to find out what is 17/34ths of 96, the equation would be written like this: 17/34 = X/96 X = (17*96)/34 = 48 To use percentages, just replace A with Current, B with Max, C with the percentage, and D with 100. Current/Max = Percent/100 So to find out what percentage 20 is of 500 20/500 = X/100 X = (20*100)/500 = 4% To find out what 5% of 250 is X/250 = 5/100 X = (250*5)/100 = 12.5 To find out what number 18 is 36% of: 18/X = 36/100 X = (18*100)/36 = 50 This little formula comes in handy in several situations. For example, I have a progress bar which is 512 pixels wide. I have finished downloading 10,496 bytes of a 1,453,687 byte file. How many pixels do I need to shade in to represent the number of bytes downloaded? Downloaded/FileSize = Shaded/BarSize 10,496/1,453,687 = X/512 X = (10,496*512)/1,453,687 = 4 pixels (rounded to the nearest pixel) |
| ||
...... you learned that in the 5th grade? man they don't teach fractions / algabra untill the 8th grade over here. useful stuff non the less, thanks! |
| ||
My post was in a little more detail than what I actually was taught. Basically, the teacher wrote down two equal fractions next to each other. He then drew arrows from one part to the other to show the pattern. So if A was unknown, he'd draw an arrow from B to C and say, "multiply these together," then he'd draw an arrow from C to D and say "Divide the result by this." You can see the pattern of multiplying the crosswise numbers which don't contain the unknown, then dividing by the third to find the answer. My post above is more the algebraic equivalent of what he taught. Even though I did get some very basic algebra back then, I didn't get anything quite that complex until about the 7th grade. It was a little thing he taught really to help us understand a little better when he started teaching us about ratios. For example, Fred spent 18c of every quarter he had. If he spent $10.80, how much money did he have originally? This could be represented by the ratios .18:.25 = 10.80:x X can be calculated using the same idea as with fractions. (.25*10.80)/.18 BTW, how can you go eight years without fractions? I can't imagine all you did was add, subtract, multiply, and divide whole numbers all that time. They must've taught you something useful. Or do you learn decimals first? Over here we learn fractions, then move to decimals as an advanced topic (or at least we did when I was in school). It's easier to grasp that when a pie is cut into eight pieces and you take three pieces, then you have 3/8th of the pie, rather than you have 0.375 of the pie. |
| ||
They did light fractions, it didnt get heavy untill about 8th grade. |
| ||
Just found this: Can you pass 8th grade math? http://encarta.msn.com/quiz_95/Could_You_Pass_8th_Grade_Math.html |