Sign in to follow this  
Followers 0
James

Find percent of a number

11 posts in this topic

#1 ·  Posted (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 by JamesB

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0