JussiR JussiR - 6 months ago 35
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


One possible solution (depends on the application):

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