EanderAlx.org

Linux, Virtualization and whatever I find interesting ...

User Tools


Site Tools


bashscr:calculate

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
blog:bashscr:calculate [05.10.2010 13:59] eanderalxblog:bashscr:calculate [05.10.2010 14:13] eanderalx
Line 19: Line 19:
  
   * To calculate with float or more complex thing use "bc"   * To calculate with float or more complex thing use "bc"
-<code> +<code bash
-echo "2.5 + 3.2" | bc+echo "2.5 + 3.2" | bc -l 
 +5.7
 </code> </code>
 +  * If you want to cut digits after the decimal point you can use scale (It's **no** rounding like you see in the example)
 +<code bash>
 +echo "scale = 4; 2.5 / 1.9 " | bc -l 
 +1.3157
 +echo "scale = 2; 2.5 / 1.9 " | bc -l 
 +1.31
 +</code>
 +  * The remaining Problem is:
 +<code bash>
 +echo "scale = 2; 2.5 / 3.1 " | bc -l 
 +.8064
 +</code>
 +  * The leading zero is lost
bashscr/calculate.txt · Last modified: 23.03.2013 18:24 by eanderalx