bashscr:calculate
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
blog:bashscr:calculate [05.10.2010 13:57] – eanderalx | bashscr:calculate [23.03.2013 18:24] (current) – Page moved from blog:bashscr:calculate to bashscr:calculate eanderalx | ||
---|---|---|---|
Line 18: | Line 18: | ||
</ | </ | ||
- | * To calculate with float is more easy to use " | + | * To calculate with float or more complex thing use " |
+ | <code bash> | ||
+ | echo "2.5 + 3.2" | bc -l | ||
+ | 5.7 | ||
+ | </ | ||
+ | * 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 | ||
+ | </ | ||
+ | * The remaining Problem is: | ||
+ | <code bash> | ||
+ | echo "scale = 2; 2.5 / 3.1 " | bc -l | ||
+ | .8064 | ||
+ | </ | ||
+ | * The leading zero is lost | ||
+ | * You can search and replace using " | ||
+ | <code bash> | ||
+ | echo "scale = 3; 2.5 / 3.1 " | bc -l | sed -r ' | ||
+ | 0.806 | ||
+ | </ |
bashscr/calculate.txt · Last modified: 23.03.2013 18:24 by eanderalx