I suspect that this isn't possible, but giving it a try:
Is it possible to determine the number of decimal points of a number, whether or not those decimal points are trailing zeros?
getPrecision(3) // 0
getPrecision(3.2) // 1
getPrecision(2.30) // 2
I've found a couple of solutions for the first two cases (including this: How do I get the decimal places of a floating point number in Javascript?) but nothing for the last case. Converting 3.20
to a string results in "3.2"
, which doesn't help, and I'm about out of ideas.