I have a set of string numbers having decimals, for example: 23.456
, 9.450
, 123.01
... I need to retrieve the number of decimals for each number, knowing that they have at least 1 decimal.
In other words, the retr_dec()
method should return the following:
retr_dec("23.456") -> 3
retr_dec("9.450") -> 3
retr_dec("123.01") -> 2
Trailing zeros do count as a decimal in this case, unlike in this related question.
Is there an easy/delivered method to achieve this in Javascript or should I compute the decimal point position and compute the difference with the string length? Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…