SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Math.abs()

We can remove the sign part of the data and display the absolute value by using abs function. Here is the syntax

Math.abs(x);

Sample code is here

<script language='JavaScript' type='text/JavaScript'>
<!--
document.write(Math.abs(-5)); // output is 5
document.write("<br>");
document.write(Math.abs(5.56)); // output is 5.56
document.write("<br>");
document.write(Math.abs(-2.5)); // output is 2.5
document.write("<br>");
document.write(Math.abs(-1.355)); // output is 1.355
document.write("<br>");
//-->
</script>

abs() math function can also be used with other calculations

document.write(Math.abs(43-64)); // output is 21

Found anything wrong or wants to improve the code by adding more features? Post your short comment here or use the Forum



Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Join Our Email List
Email:  
For Email Newsletters you can trust
Math functions
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2013 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer