Math.abs( ) Method | Flash 5; can be used when exporting Flash 4 movies |
compute the absolute value of a number |
Any integer or floating-point number.
The absolute value of x (a positive number of magnitude x).
The abs( ) method calculates the distance between x and 0 (i.e., the absolute value of x). It leaves zero and positive numbers unchanged and converts negative numbers into positive numbers of the same magnitude. It is useful for calculating the difference between two numbers without regard to which is larger. For example, it is useful when calculating the distance between two points, because distances are always positive.
Math.abs(-5); // Returns 5 // Calculate the difference between two numbers function diff (num1, num2) { return Math.abs(num1-num2); } diff(-5, 5); // Returns 10