ewhitt has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone know of a Perl module that will return what percentage a number is of another number? I can't seem to find anything in the Math:: modules. Thanks!

Replies are listed 'Best First'.
Re: Percentage module in Math::?
by syphilis (Archbishop) on Dec 08, 2007 at 08:20 UTC
    Hi ewhitt,

    return what percentage a number is of another number

    Shouldn't really require a module for that (imo). Better to just write a sub that divides the "a number" by the "another number" and multiplies by 100.

    Cheers,
    Rob
Re: Percentage module in Math::?
by TOD (Friar) on Dec 08, 2007 at 09:42 UTC
    that's a rather trivial equation problem:
    $some_value / $some_othervalue = $x / 100 <=> $x = $some_value * 100 / $some_othervalue
    ;-)
    --------------------------------
    masses are the opiate for religion.
Re: Percentage module in Math::?
by KurtSchwind (Chaplain) on Dec 08, 2007 at 13:28 UTC

    I agree with most of the others. This is module madness if we need a module to do division.

    I will ad this to what the others have said though. Be careful of divide by zero. You may want to do something like this.

    my $percent = ($second_number ? $first_number/$second_number : undef);
    And then check $percent for undef.
    --
    I used to drive a Heisenbergmobile, but every time I looked at the speedometer, I got lost.
        If $second_number is a negative zero, shouldn't that give negative undef? (Just kidding.)

        Unless $first_number is also negative. (Being equally serious.)

        Cheers,
        Rob
Re: Percentage module in Math::?
by sanPerl (Friar) on Dec 08, 2007 at 10:56 UTC
    Even if there is any module preseent, can't you simply write subroutine with few lines of code? I don't think I need to post this code, I think monk of your level can easily do it.
    Please let us know why you want readymade module? From my experience of team managements and collaborative development environments, I know manytimes you need to restrict programmers to use standard modules to maintain consistancy and reliability of giant programs, If that is the case then I think here you can create your own library sub and distribute to your group.
Re: Percentage module in Math::?
by sh1tn (Priest) on Dec 08, 2007 at 13:11 UTC