整数を捨てて浮動小数点を維持します。

整数を捨てて浮動小数点を維持します。

現在持っている10進値から整数を削除しようとしています。

現在の構文:

h=$(echo "scale=2; (($e/$g/$g))" | bc) 
echo $h 

次のコードは秒を分、時間に変換するために使用されますが、「21.15」時間を返します。

私は0.15を維持し、ここに60を掛けたい(9分残り)。すると結局21時間9分になります。

ベストアンサー1

残りのbc演算子は%

   expr % expr
          The  result  of the expression is the "remainder" and it is com‐
          puted in the following way.  To compute a%b, first a/b  is  com‐
          puted to scale digits.  That result is used to compute a-(a/b)*b
          to the scale of the maximum of scale+scale(b) and scale(a).   If
          scale  is  set  to  zero  and both expressions are integers this
          expression is the integer remainder function.

前任者。

$ echo '21.15 % 1' | bc
.15

$ echo '(21.15 % 1) * 60' | bc
9.00

おすすめ記事