[英]Count how many decimal places in a decimal number in bash shell
我有一个十进制数:
num=0.000001
我想得到小数位数,使用 bash shell
所需 output:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.