Jump to content

Find percent of a number


James
 Share

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
Link to comment
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]

Link to comment
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]

Link to comment
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.

Link to comment
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]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...