Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

awk calculation automatically rounding off the output

$
0
0
I have some calculation in my script which is similar to the below example . I find that sometimes when using large decimal digits, the output gets automatically rounded off and it is affecting the program. I am not able to understand what is happening here..

Code:

awk '{
a=6.32498922
a1=6.324
b=52
c=12.65
 
d=(a*b/c)
d1=(a1*b/c)
 
printf(" d = %s;",d)
printf(" d1 = %s\n",d1)
 
result1=d*300
result2=d1*300
 
printf(" result1=> %s\n",result1)
printf(" result2=> %s\n",result2)
}' test1

prints:
Code:

d = 26; d1 = 25.9959
result1=> 7799.99
result2=> 7798.77

Where is the decimals points in "d" . And if it got rounded off, why is the decimals appearing in "result1"

Could you help me understand what really is happening ? How can i make sure that the decimals does not get rounded off automatically?

Viewing all articles
Browse latest Browse all 16232

Trending Articles