Get decimal portion of a number with JavaScript Get decimal portion of a number with JavaScript javascript javascript

Get decimal portion of a number with JavaScript


var decimal = n - Math.floor(n)

Although this won't work for minus numbers so we might have to do

n = Math.abs(n); // Change to positivevar decimal = n - Math.floor(n)


You could convert to string, right?

n = (n + "").split(".");