Reputation: 583
I have a decimal number:
num=0.000001
I want to get the decimal places count, using bash shell
Required output:
decimalPointsCount=$(code to get decimal places length of $num variable)
Any awk,sed,perl..etc suggestions would be appreciated,Thanks
Upvotes: 0
Views: 956
Reputation: 4004
The shell alone can do that:
num=0.000001
decimals=${num#*.} #Removes the integer part and the dot (=000001)
decimalPointsCount=${#decimals} #Counts the length of resulting string (=6)
Upvotes: 1