User Tools

Site Tools


maths

This is an old revision of the document!


You can use bc in bash to do math calculations with decimals.

http://unixhelp.ed.ac.uk/CGI/man-cgi?bc+1

bc -l <<< "20 / ( 20 + 80) * 100 "
The output looks like:
20.00000000000000000000
You can then use this with printf to limit the number of decimals shown: \\The example below shows the results to 3 decimal places. You can replace the 3 with what ever value you wish to place
printf "%.3f\n" $(bc -l <<< "20 / ( 20 + 80) * 100 ")

You can also use bc with variables:
bc -l <<< "($used / ( $free + $used) ) * 100 ")

maths.1431206101.txt.gz · Last modified: 2024/05/23 07:26 (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Public Domain Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki