var x = 1234.567;
var parts = x.toString().split('.');
parts[0].length;
parts[1].length;
Note
Javascript has toPrecision () , which gives a number with the specified length.
For instance:
var x = 1234.567;
x.toPrecision(4);
x.toPrecision(5);
x.toPrecision(7);
But
x.toPrecision(5);
x.toPrecision(3);
etc.
According to the comment
Is there a way to check what the string contains .?
var x = 1234.567
x.toString().indexOf('.');
Note
.indexof()return the first index of the else target -1.
source
share