SQL PHP HTML ASP JavaScript articles and free scripts to download
JavaScript Math Functions


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


Sample code is here

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

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

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

We can integrate a demo script to calculate the absolute value of any integer.

Demo of Math.abs function

Here is the code

<script type="text/javascript">
function disp_data(){
var a1 = document.getElementById('t1').value;
document.getElementById("a2").innerHTML= a1;

<input type=text name=t1 id='t1' value=-12.78><input type=button value='Display rounded number' onClick='disp_data()';>
<div id='a2' style=" background-color: #c0f0c0; width:200" > Enter a number</div>

Be the first to post comment on this article :


Post Comment This is for short comments only. Use the forum for more discussions.
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

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

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