# Find percent of a number

## Recommended Posts

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 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 on other sites

Cool, I learnt something new! Thanks SWG

##### 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 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 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 on other sites

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.

##### 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 on other sites

Yeah, I just noticed I named them wrongly :\

##### 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 on other sites

Yeah sorry

I will change it.

## Create an account

Register a new account