May 2001
Intermediate to advanced
720 pages
23h 24m
English
Math.abs( ) Method — compute the absolute value of a number
Flash 5; may be used when exporting Flash 4 movies
Math.abs(x)
A positive or negative number.
The absolute value of x (a positive number
of magnitude x).
The abs( ) method calculates the distance
between x and
(also known as the absolute value of
x). It leaves 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 than the other. 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 10Read now
Unlock full access