I have to variables and I want to find the value of one divided by the other. What commands should I use to do this?
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
- Null-terminated string, opening file for reading
2.50000000000000000000
this '-l' option in 'bc' allows floating results
Example of integer division using bash to divide $a by $b:
I assume that by Linux console you mean Bash.
If
X
andY
are your variables,$(($X / $Y))
returns what you ask for.You can use awk which is a utility/language designed for data extraction
e.g. for 1.2/3.4
I also had the same problem. It's easy to divide integer numbers but decimal numbers are not that easy. if you have 2 numbers like 3.14 and 2.35 and divide the numbers then, the code will be Division=
echo 3.14 / 2.35 | bc
echo "$Division" the quotes are different. Don't be confused, it's situated just under the esc button on your keyboard. THE ONLY DIFFERENCE IS THE | bc and also here echo works as an operator for the arithmetic calculations in stead of printing. So, I had added echo "$Division" for printing the value. Let me know if it works for you. Thank you.Better way is to use "bc", an arbitrary precision calculator.
ex:
where "scale=5" is accuracy.
comes with several usage examples.