Hi Friends,
I need a help again in awk.
I just need to round up a value.
Eg Say x=5.664584525
I need to display x=5.66 means round. How can i do round in UNIX.
Hi Friends,
I need a help again in awk.
I just need to round up a value.
Eg Say x=5.664584525
I need to display x=5.66 means round. How can i do round in UNIX.
Use the printf format "%.2f" to perform rounding.
e.g.
echo "5.664584525" | awk '{printf "%.2f",$0}'
output will be 5.66
Thanks a load
Dhruva..
Its working fine ......Actually I was trying to do with round function and its was becoming really complicated... now its so simple.. Thanks dude..
Hi Friends ,
I am again facing a problem there when I am trying to get the rouind of a fraction.
Say X = 8/3
It should give the value as 2.66
So please can give any inputs ...
Thanks In Advance...
Hi Friends,
Can any one please give the following solution.
Say I have a variable x = 8/3
I need the value of x as 2.66.
And I am using the same in shell script.
Can I get the above value with round function or awk command.
Thanks in advance friends.
8/3 = 2.666666... rounded to 2 decimals is normally 2.67
b = `echo "8/3" | bc -l`
printf ".2f\n" $b
printf does rounding for you
Through shell?
echo "scale=2; 8/3"|bc
Soumya Dash, please do not post in multiple threads on the same topic. I have merged the threads.