JussiR JussiR - 10 months ago 51
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 Source

One possible solution (depends on the application):

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