JussiR JussiR - 1 year ago 76
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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download