我有一个十进制数:
num=0.000001
我想使用bash-shell 获得小数位数
所需输出:
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)