Get decimal portion of a number with JavaScript

Solution 1:

Use 1, not 2.

js> 2.3 % 1
0.2999999999999998

Solution 2:

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 positive
var decimal = n - Math.floor(n)

Solution 3:

You could convert to string, right?

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