簡體   English   中英

在 bash shell 中計算十進制數中的小數位數

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM