Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Normalizing a range of numbers to a percentage

by stevieb (Canon)
on Mar 07, 2019 at 23:19 UTC ( [id://1231037]=note: print w/replies, xml ) Need Help??


in reply to Re: Normalizing a range of numbers to a percentage
in thread Normalizing a range of numbers to a percentage

Thanks tybalt89!

I did happen to simplify this down a bit because of the zero aspect, but for completeness purposes, may I bug you to add in a couple of examples as to where my OP code *wouldn't* work?

Say if $new_min was 5 for example?

Replies are listed 'Best First'.
Re^3: Normalizing a range of numbers to a percentage
by pryrt (Abbot) on Mar 07, 2019 at 23:23 UTC

    With $new_min = 5, it would give a range of 0..95 rather than 5..100 if you don't include the offset.

    With -100 to +100 as the new min/max, it would give 0..200 rather than -100 to +100.

      "With $new_min = 5, it would give a range of 0..95 rather than 5..100 if you don't include the offset."

      So the following is what is meant here?

      my $x = (($tap - $min) * ($new_max - $new_min + 5) / ($max - $min)); # ^^^

        No.

        my $x = (($tap - $min) * ($new_max - $new_min) / ($max - $min)) + $new +_min;

        The offset on the new range has to be outside the multiply.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found