i need to multiplay a number with 1.00.. so that the output should contain two decimal places at end..
for example...
236 * 1.00 = 236.00
245.8 * 1.00 = 245.80
but when i perform multiplication it shows output as.
236
245.8
can anyone help me to get the actual output of 236.00 and 245.80...
thanks in advance...
Arun Manas:b:
Use bc:
echo "236 * 1.00" | bc
Use awk:
awk 'BEGIN{p=236 * 1.00; printf "%0.2f", p}'
kurumi
April 25, 2011, 3:09am
4
$ ruby -e 'BEGIN{print 236 * 1.00}'
Hi Kevin,
the below command works fine..
awk 'BEGIN{p=236 * 1.00; printf "%0.2f", p}'
can u please help me to apply this script for a excel sheet which contains numbers and all those number should be displayed in the above format
arunmanas:
Hi Kevin,
the below command works fine..
awk 'BEGIN{p=236 * 1.00; printf "%0.2f", p}'
can u please help me to apply this script for a excel sheet which contains numbers and all those number should be displayed in the above format
How does your excel sheet look like? what's your input and desired output?
Anyway, I think you should try it out yourself, you already know how to print numbers with decimal point.
Excel file look like:
134.4
126.7
144
555
77.88
the required output is
134.40
126.70
144.00
555.00
77.88
kamaraj@kamaraj-laptop:~/Desktop/Scripts$ awk '{printf("%.2f\n",$1)}' decimal_file
134.40
126.70
144.00
555.00
77.88
kamaraj@kamaraj-laptop:~/Desktop/Scripts$ cat decimal_file
134.4
126.7
144
555
77.88
# while read -r l ; do echo "scale=2 ; $l*1/1"|bc ; done<infile
134.40
126.70
144.00
555.00
77.88
HI Kamaraj,,,
thanks a lot..
code wrks fine
---------- Post updated at 03:46 AM ---------- Previous update was at 03:43 AM ----------
HI kamraj,,
do u knw how to include thousand places for these numbers
input:
12223
45679.55
3344
output:
12,223
45,679.55
3,344
Try this sed command:
$
$ echo 123456.00 | sed -e :a -e 's/^\([^.]*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'
123,456.00
$ echo 123456 | sed -e :a -e 's/^\([^.]*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'
123,456
$ echo 123456789987654321123456789.12345 | sed -e :a -e 's/^\([^.]*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'
123,456,789,987,654,321,123,456,789.12345
$ echo -123456.66 | sed -e :a -e 's/^\([^.]*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'
-123,456.66
$
#!/bin/ksh93
while read num
do
printf "%.2,f\n" $num
done < infile
infile:
134.4
126.7
144
555
77.88
12223
45679.55
3344
output:
134.40
126.70
144.00
555.00
77.88
12,223.00
45,679.55
3,344.00
BTW, this does not works for lakhs