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 revision
Previous revision
blog:bashscr:calculate [05.10.2010 13:59] eanderalxbashscr:calculate [23.03.2013 18:24] (current) – Page moved from blog:bashscr:calculate to bashscr:calculate 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> 
 +  * 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 
 +  * You can search and replace using "sed" 
 +<code bash> 
 +echo "scale = 3; 2.5 / 3.1 " | bc -l | sed -r 's/^\./0./g' 
 +0.806
 </code> </code>
bashscr/calculate.txt · Last modified: 23.03.2013 18:24 by eanderalx