I know it's really stupid question, but I don't know how to do this in bash:
20 / 30 * 100
It should be 66.67
but expr is saying 0
, because it doesn't support float.
What command in Linux can replace expr and do this equalation?
I know it's really stupid question, but I don't know how to do this in bash:
20 / 30 * 100
It should be 66.67
but expr is saying 0
, because it doesn't support float.
What command in Linux can replace expr and do this equalation?
bc
will do this for you, but the order is important.or, for your specific case:
Whatever method you choose, this is ripe for inclusion as a function to make your life easier:
I generally use perl:
just do it in awk
save it to variable
This is a simplification of the answer by paxdiablo. The -l sets the scale (number of digits after the decimal) to 20. It also loads a math library with trig functions and other things.
As reported in the bash man page:
You can multiply by 100 earlier to get a better, partial result:
66
Or by a higher multiple of 10, and imagine the decimal place where it belongs:
66666