float division in bash
Default Division in BASH is based on Integer Number(s). How can we deal with floating point division in bash ?
In that case "bc" command can be used.
Two types of float division can be done in "bc"
1. Mentioning Scale
2. Full Scale
1. Mentioning Scale
echo "'scale=2; 100/3" | bc
Will give the output as 33.33 (2 Decimal Spaces)
2. Full Scale
echo "100/3" | bc -l
Will give the output as33.33333333333333333333
Reference:
As usual , I got the solution from here
http://stackoverflow.com/questions/12722095/how-can-i-get-a-float-division-in-bash
Default Division in BASH is based on Integer Number(s). How can we deal with floating point division in bash ?
In that case "bc" command can be used.
Two types of float division can be done in "bc"
1. Mentioning Scale
2. Full Scale
1. Mentioning Scale
echo "'scale=2; 100/3" | bc
Will give the output as 33.33 (2 Decimal Spaces)
2. Full Scale
echo "100/3" | bc -l
Will give the output as33.33333333333333333333
Reference:
As usual , I got the solution from here
http://stackoverflow.com/questions/12722095/how-can-i-get-a-float-division-in-bash
No comments:
Post a Comment