How to display number to two decimal places in bash function

前端 未结 4 1599
南方客
南方客 2021-02-20 16:27

How should I take a number that is in hundreths of seconds and display it in seconds to two decimal places? Psuedo code to follow the dTime function I am not sure about but you\

4条回答
  •  花落未央
    2021-02-20 16:42

    "bc" and "dc" both truncate rather than round, so nowadays I prefer Perl

    If "N" has your number of hundreths of seconds in it then:

    $ perl -e "printf('%.2f', $N/100)"
    

    I was never a Perl supporter but it is now ubiquitous and I have finally been swayed to using it instead of sed/awk etc.

提交回复
热议问题