Linux 计算bashshell中十进制数的小数位数

Linux 计算bashshell中十进制数的小数位数,linux,bash,shell,command-line,Linux,Bash,Shell,Command Line,我有一个十进制数: num=0.000001 我想使用bashshell获得小数位数 所需输出: decimalPointsCount=$(code to get decimal places length of $num variable) 任何awk、sed、perl…等建议都将不胜感激,谢谢仅shell就可以做到这一点: num=0.000001 decimals=${num#*.} #Removes the integer part and the dot

我有一个十进制数:

num=0.000001
我想使用bashshell获得小数位数

所需输出:

decimalPointsCount=$(code to get decimal places length of $num variable)

任何awk、sed、perl…等建议都将不胜感激,谢谢

仅shell就可以做到这一点:

num=0.000001
decimals=${num#*.}              #Removes the integer part and the dot (=000001)
decimalPointsCount=${#decimals} #Counts the length of resulting string (=6)

谢谢你一如既往的好话@胡言乱语13