<div>n1 = <span id="n1"></span></div>
<div>n2 = <span id="n2"></span></div>
<div>n3 = <span id="n3"></span></div>
var num = 1.2;

var n1 = Math.abs(num); 

/*--反向abs()整數轉負數--*/
var n2 = -Math.abs(num);
/*------or-------*/
var n3 = Math.abs(num) * -1;

document.getElementById('n1').innerHTML = n1;
document.getElementById('n2').innerHTML = n2;
document.getElementById('n3').innerHTML = n3;

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.