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
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.