Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with arithmetic precision

Status
Not open for further replies.

erixire

Technical User
Jun 4, 2002
72
CA
Hi everyone,

I have a big problem. I am using gawk under windows and I want to add to column like this:
5.125 9.236
7.458 6.473
1.487 9.196

I want the output of $1 + $2, so
14.361
13.931
10.683

But it only gave me:
14
13
10

A kind of truncation. The thing is that this problem is only on some windows machine (running the same OS version). Does somebody can help me with this one (having more precision to my output)?

Thanks a lot,
 
Use

printf ("%6.2f\n",$1+$2)

I don't know why your output is being truncated, perhaps the awk variables CONVFMT or OFMT have been set. How are you printing it?

CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
Thanks CaKiwi, but actually, what I did, is find another awk for MSDOS and it work fine. I was printing like this:
{print $1 + $2}. But I didn't tried the "printf" function. So thanks anyway,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top