The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Rounding off to the next whole number damansingh Shell Programming and Scripting 2 07-17-2008 07:18 AM
Very ANNOYING Problem - Please Help shadow0001 Shell Programming and Scripting 7 03-12-2008 06:28 PM
Rounding problem shash UNIX for Dummies Questions & Answers 2 01-18-2007 05:33 AM
Rounding off using BC. noodlesoup Shell Programming and Scripting 3 09-11-2006 01:38 AM
a very annoying problem Stormpie UNIX for Dummies Questions & Answers 2 04-24-2002 01:29 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-26-2008
Indalecio Indalecio is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sweden
Posts: 59
Annoying rounding issue in awk

Hello
I am getting this very annoying issue in awk:

awk '{a=12825;b=a*1.25; print b}' test 16031.2
-->
Code:
awk '{a=12825;b=a*1.25; print b}' test
16031.2
        
Thing is the multiplication result is wrong... Result should be 16031.25.
I think the issue only happens on bigger numbers.

What can I do to get passed this?
Thanks by advance
  #2 (permalink)  
Old 08-26-2008
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 579
awk '{a=12825;b=a*1.25; printf "%5.2f\n", b}' test
-->
Code:
awk '{a=12825;b=a*1.25; printf "%5.2f\n", b}' test
        
  #3 (permalink)  
Old 08-26-2008
Indalecio Indalecio is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sweden
Posts: 59
Edit: nevermind, I need to test more
  #4 (permalink)  
Old 08-26-2008
Indalecio Indalecio is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sweden
Posts: 59
Alright

This doesn't work:

awk '{ a="12825"; b="16031.25"; c=a*1.25; if (b != c) printf "%5.2f\t%5.2f\n",b,c }' test
-->
Code:
awk '{ a="12825";  
          b="16031.25"; 
          c=a*1.25; 
          if (b != c) printf "%5.2f\t%5.2f\n",b,c  
      }' test
        
Edit: and replacing the strings by numbers does work ???
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0