Skip to content
Advertisement

Linux/Raspberry Pi command to help round to 2 decimal

I am running the following command to get Free Memory, and want to change it from KB to MB to the second decimal.

grep MemFree /proc/meminfo | awk {'print $2*.001'}

Output: 96.163 | Want it to be Output 96.16

How do I round? I have seen where it says to use scale=2, but then it just prints out scale=2, I have tried puttting it before anfer and inbetween several different ways with no luck. how can I do this.

I am editing the .bashrc file to I can see the output in MB no KB

Advertisement

Answer

awk '/MemFree/ { printf("%0.2fn", $2 * .001) }' /proc/meminfo
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement