The absolute value is simply the value without a sign, for example the absolute value of 4, or +4, is the same as the absolute value of -4: 4. If you are creating an application that requires the absolute value of a number, use the Java Script Math.abs method.
Welcome to Bucaro TecHelp!

Bucaro TecHelp
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Victims of Sandy Hook

Stop the Slaughter of Innocents. Congress is bought and paid for by gun lunatics and gun promotion groups. If you want to live in a safe America, help buy Congress back for America. Send a donation to Mayors Against Illegal Guns, 909 Third Avenue, 15th Floor New York, NY 10022

Determine Absolute Value

The absolute value is simply the value without a sign, for example the absolute value of 4, or +4, is the same as the absolute value of -4: 4. If you are creating an application that requires the absolute value of a number, use the Java Script Math.abs method.

For example if you are designing a graphics application that lets the user draw a horizontal line on the screen and you want to display the length of the line in the applications status bar.

If the user draws a line from point a = 100 pixels to point b = 50 pixels, we can subtract a - b to get the line length of 50 pixels. But what if the user draws a line from point a = 50 pixels to point b = 100 pixels? Subtracting a - b = -50 pixels. A line length of -50 pixels is a little confusing to the user.

We can solve that problem by passing the subtract statement to the Math.abs method as shown below.

var length = Math.abs(a - b);

The Math.abs method will always return the result as an unsigned number.

RSS Feed RSS Feed



Follow Stephen Bucaro Follow @Stephen Bucaro


Web Design Sections

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2016 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268