Hi Experts,
Quick question:
I am trying to get the output with decimal and floating point but not working:
echo "20.03" | awk '{printf "%03d.2f\n" , $0 }'
020.2f
How to get the output as :
020.03
Thank you.
Hi Experts,
Quick question:
I am trying to get the output with decimal and floating point but not working:
echo "20.03" | awk '{printf "%03d.2f\n" , $0 }'
020.2f
How to get the output as :
020.03
Thank you.
$
$ echo "20.03" | awk '{printf "%06.2f\n" , $0 }'
020.03
$
$
You can also control numeric output format using gawk OFMT built-in variable:
$ echo "20.03" | awk 'BEGIN{OFMT="%06.2f"}{print $0+0}'
020.03
OR
$ awk 'BEGIN{OFMT="%06.2f";print 20.03}'
020.03
For this simple example you don't need awk
$ printf "%06.2f\n" 20.03
020.03
Thanks all I got it now .
echo "20.03" | awk '{printf "%06.2f\n" , $0 }'
awk 'BEGIN{OFMT="%06.2f";print 20.03}'
printf "%06.2f\n" 20.03
All worked... Thanks.
---------- Post updated at 03:03 PM ---------- Previous update was at 02:59 PM ----------
>> For this simple example you don't need awk