[英]Count how many decimal places in a decimal number in bash shell
I have a decimal number:我有一个十进制数:
num=0.000001
I want to get the decimal places count, using bash shell我想得到小数位数,使用 bash shell
Required output:所需 output:
decimalPointsCount=$(code to get decimal places length of $num variable)
Any awk,sed,perl..etc suggestions would be appreciated,Thanks任何 awk、sed、perl..等建议将不胜感激,谢谢
The shell alone can do that:单独的 shell 可以做到这一点:
num=0.000001
decimals=${num#*.} #Removes the integer part and the dot (=000001)
decimalPointsCount=${#decimals} #Counts the length of resulting string (=6)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.