Actionscript 3: Get ratio value between two numbers

Simple utility for getting a ratio between two numbers. Thanks to my friend Jamie for the method.


private function returnValue(value:Number, actualMin:Number, actualMax:Number, ratioMin:Number, ratioMax:Number):Number{
     return (((value - actualMin) / (actualMax - actualMin)) * (ratioMax - ratioMin)) + ratioMin;
}

Here is also a simpler version when you know the percentage of the number range.


public function returnValue( percentage:Number, min:Number, max:Number ):Number {
    return ((( max - min ) / 100 ) * percentage ) + min;
}

This version returns a percentage of the two range of numbers.


publicĀ  function returnValuePercentage( _value:Number, min:Number, max:Number ):Number {
return ((( _value - min ) / ( max - min )) * 100 );
 }

This entry was posted in Actionscript 3.0 and tagged . Bookmark the permalink.

2 Responses to Actionscript 3: Get ratio value between two numbers

  1. kris says:

    Dude you saved me a ton of time. Nice of you to share tidbits like this. Keep it up.

  2. albert says:

    Hello,
    I try to make with AS3.0 some kind of competition. Therefor I have to calculate “Points”. Example:
    I sign in a user with 100 points. Later another one with 120. Another one with 200 and so on….. . I want AS3 to put this numbers in a line by its value, i.e. on top 200-120-100. Also i need to increase the numbers manually i.e. The user with 100 did something so I can add 20 oder 100 Points to his 100 und as3.0 will updatre the list again.Maybe with php …………Any help appreciated tks a lot.CanĀ“t find a donation button.
    Regards
    Albert.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>