James Posted August 17, 2007 Posted August 17, 2007 (edited) Hey, I have been brushing up on my math skills (Im really not too good). MsgBox(0, "Percent", Percent(10, 100)) Func Percent($number, $percent) $Multiply = $number * $percent $Divide = $Multiply / 100 $Final = StringSplit($Divide, ".") Return $Final[1] EndFuncoÝ÷ Ø ®É¯²ºÈ§íjëh×6MsgBox(0, "Percent", Percent(10, 100)) Func Percent($number, $percent) Return Int(($number * $percent) / 100) EndFunc Thanks SWG -James Edited August 17, 2007 by JamesB Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
SkinnyWhiteGuy Posted August 17, 2007 Posted August 17, 2007 Not to make you feel bad, but just to show you another way: Func Percent($number, $percent) Return Int(($number * $percent) / 100) EndFunc The Int() function does what you were doing with stringsplit, but probably faster.
James Posted August 17, 2007 Author Posted August 17, 2007 Cool, I learnt something new! Thanks SWG Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
Monamo Posted August 17, 2007 Posted August 17, 2007 JamesB said: Hey, I have been brushing up on my math skills (Im really not too good). MsgBox(0, "Percent", Percent(10, 100)) Func Percent($number, $percent) $Multiply = $number * $percent $Divide = $Multiply / 100 $Final = StringSplit($Divide, ".") Return $Final[1] EndFuncoÝ÷ Ø ®É¯²ºÈ§íjëh×6MsgBox(0, "Percent", Percent(10, 100)) Func Percent($number, $percent) Return Int(($number * $percent) / 100) EndFunc - MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]
Monamo Posted August 17, 2007 Posted August 17, 2007 pseudo-edit:Dunno if it's the forum acting up or not, but I can't seem to edit my previous post.The original function you posted yielded 5 percent when it should have yielded 20 percent (based upon my "10,50" example). - MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]
SkinnyWhiteGuy Posted August 17, 2007 Posted August 17, 2007 Actually, I think JamesB's original function wasn't trying to answer the question: <number1> is what percent of <number2>? I think it was trying to answer the question: What is <number2> percent of <number1>? So, both could be right, depending on what you were looking to answer.
James Posted August 17, 2007 Author Posted August 17, 2007 SWG is correct, it finds the percentage of a number. In the function, it looks at the first number in the function: 10 is the percentage of 100. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
SkinnyWhiteGuy Posted August 17, 2007 Posted August 17, 2007 Thought so, and btw, the way your function is done, the order in which you put the numbers really doesn't matter, since multiplication will work with either number first.
James Posted August 17, 2007 Author Posted August 17, 2007 Yeah, I just noticed I named them wrongly :\ Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
Monamo Posted August 17, 2007 Posted August 17, 2007 JamesB said: Yeah, I just noticed I named them wrongly :\Ah, that explains why it didn't look right. - MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]
James Posted August 17, 2007 Author Posted August 17, 2007 Yeah sorry I will change it. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now