JussiR JussiR - 23 days ago 7
Javascript Question

How do I get the decimal precision of a floating point number in Javascript?

Basically, what i would like to have is the opposite of Number.prototype.toPrecision(), meaning that when i have number, what decimal precision does it currently have? E.g.

(12.3456).getPrecision() // 4

Answer

One possible solution (depends on the application):

var precision = (12.3456 + "").split(".")[1].length;
Comments