Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

calc percentage

by bigup401 (Pilgrim)
on Mar 13, 2019 at 09:10 UTC ( #1231199=perlquestion: print w/replies, xml ) Need Help??

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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: calc percentage
by hdb (Monsignor) on Mar 13, 2019 at 09:32 UTC

    5% is shorthand for 0.05. Therefore, 5% of 50000 is 0.05 * 50000 = 2500.

    More generally: x% is shorthand for x/100. Therefore, x% of y is x / 100 * y.

      thanks, this has given me much idea

Re: calc percentage
by thanos1983 (Parson) on Mar 13, 2019 at 09:19 UTC

    Hello bigup401,

    Do you mean something like that?

    percentage = partialAmount / totalAmount totalAmount = partialAmount / percentage partialAmount = percentage * totalAmount

    If so this is a not a Perl related question. Unless if you mean if there is a module that can do this calculation for you?

    Update: Also look at the Math::PercentChange is this what you are looking for? From to percentage difference?

    BR / Thanos

    Seeking for Perl wisdom...on the process of learning...not there...yet!

      Any. which can do for me that calculation . if there is a module or a example without a module i appreciate

        Hello bigup401,

        I do not know if you saw my updated answer but here is an example that you can use a module and it will do the calculation for you (see below):

        #!/usr/bin/perl use strict; use warnings; use feature 'say'; use Math::PercentChange qw(f_percent_change); my $from = 10; my $to = 15; say f_percent_change($from, $to, "%.03f"); __END__ $ perl 50.000%

        Hope this helps, BR.

        Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1231199]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2022-06-25 13:54 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (82 votes). Check out past polls.