The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem in division rochitsharma UNIX for Dummies Questions & Answers 9 1 Week Ago 07:17 PM
display the result of wc -l with words before and after the result melanie_pfefer UNIX for Dummies Questions & Answers 3 04-30-2008 04:33 AM
Outputting formatted Result log file from old 30000 lines result log<help required> vikas.iet Shell Programming and Scripting 5 12-02-2007 07:43 PM
Cannot adjust division jav_v Filesystems, Disks and Memory 1 08-20-2002 05:50 AM
division problem inquirer Shell Programming and Scripting 3 04-02-2002 07:03 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-22-2008
Registered User
 

Join Date: Sep 2007
Posts: 163
how to get exact result in my division

Hello Friends,


Why I am not getting exact result in the following division. It is rounding off automatically. Is there any way to get the exact result or
can be set by user to get how many digits to carry after the decimal.

Code:
gawk '{

  wait_ns1 = (82290 +1 )/78  # actuall result = 1055.012821
  wait_ns2 = (82320 +1 )/78  # actuall result = 1055.397436
  wait_ns3 = (82350 +1 )/78  # actuall result = 1055.782051

  print wait_ns1;
  print wait_ns2;
  print wait_ns3;

} ' my_file
output:
Code:
1055.01
1055.4
1055.78

Or How to get the actuall result ,ie,
Code:
1055.012821
1055.397436
1055.782051
Thanks in advance..
Reply With Quote
Forum Sponsor
  #2  
Old 01-22-2008
Registered User
 

Join Date: May 2007
Posts: 2
you can try this

Code:
nawk '
{
wait_ns1 = (82290 +1 )/78;
printf("%10.6f\n", wait_ns1);
}'
Reply With Quote
  #3  
Old 01-22-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Code:
 # gawk 'BEGIN {OFMT = "%.6f"; print (82290 +1 )/78 ;}'
1055.012821
Reply With Quote
  #4  
Old 01-22-2008
Registered User
 

Join Date: Sep 2007
Posts: 163
Quote:
Originally Posted by LGMENG View Post
you can try this

Code:
nawk '
{
wait_ns1 = (82290 +1 )/78;
printf("%10.6f\n", wait_ns1);
}'
Thank You BOSS..
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0