Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-23-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..
Sponsored Links
  #2 (permalink)  
Old 01-23-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);
}'

  #3 (permalink)  
Old 01-23-2008
Registered User
 

Join Date: Sep 2006
Posts: 2,604

Code:
 # gawk 'BEGIN {OFMT = "%.6f"; print (82290 +1 )/78 ;}'
1055.012821

  #4 (permalink)  
Old 01-23-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..
Sponsored Links
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 Off


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 11-25-2008 10: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 08: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 10:43 PM
Cannot adjust division jav_v Filesystems, Disks and Memory 1 08-20-2002 09:50 AM
division problem inquirer Shell Programming and Scripting 3 04-02-2002 11:03 PM



All times are GMT -4. The time now is 04:13 PM.


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-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0