how to get exact result in my division


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to get exact result in my division
# 1  
Old 01-23-2008
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..
# 2  
Old 01-23-2008
you can try this

Code:
nawk '
{
wait_ns1 = (82290 +1 )/78;
printf("%10.6f\n", wait_ns1);
}'

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

# 4  
Old 01-23-2008
Quote:
Originally Posted by LGMENG
you can try this

Code:
nawk '
{
wait_ns1 = (82290 +1 )/78;
printf("%10.6f\n", wait_ns1);
}'

Thank You BOSS..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to compare the current result with previous line result.?

Hi Gurus, I have requirement to compare current result with previous reuslt. The sample case is below. 1 job1 1 1 job2 2 1 job3 3 2 job_a1 1 2 job_a2 2 2 job_a3 3 3 job_b1 1 3 job_b2 2 for above sample file, GID is group ID, for input line, the job run... (1 Reply)
Discussion started by: ken6503
1 Replies

2. UNIX for Dummies Questions & Answers

Division of wc output

I have a function that outputs 3 lines for each result and I want to know how many results there are. so for example function | wc -l 24 but I want to see the result 8. so is there a easy way to divide the result? (5 Replies)
Discussion started by: yatici
5 Replies

3. Shell Programming and Scripting

echo exact xml tag from an exact file

Im stumped on this one. Id like to echo into a .txt file all names for an xml feed in a huge folder. Can that be done?? Id need to echo <name>This name</name> in client.xml files. $path="/mnt/windows/path" echo 'recording names' cd "$path" for names in $path than Im stuck on... (2 Replies)
Discussion started by: graphicsman
2 Replies

4. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

5. UNIX for Dummies Questions & Answers

Help in division

hi, The below commands result only the whole number(not giving the decimal values). pandeeswaran@ubuntu:~$ echo 1,2,3,4|sed 's/,/\//g'|bc 0 pandeeswaran@ubuntu:~$ echo 1000,2,3|sed 's/,/\//g'|bc 166 How to make it to return the decimal values? Thanks (5 Replies)
Discussion started by: pandeesh
5 Replies

6. UNIX for Advanced & Expert Users

awk: division by zero

I received error "awk: division by zero" while executing the following statement. SunOS 5.10 Generic_142900-15 sun4us sparc FJSV,GPUZC-M echo 8 | awk 'END {printf ("%d\n",NR/$1 + 0.5);}' file1.lst awk: division by zero Can someone provide solution? Thanks Please use code... (11 Replies)
Discussion started by: kumar77
11 Replies

7. Shell Programming and Scripting

division by zero

Hello, I am searching for a way to calculate for example 10/100 within a shellscript and the result should be 0.1 and not just 0. Every alternative i tried just results 0 Thank you in advance 2retti (6 Replies)
Discussion started by: 2retti
6 Replies

8. UNIX for Dummies Questions & Answers

display the result of wc -l with words before and after the result

hello showrev -p | wc -l returns: 381 What to do in case I want to have this output: number of lines returned by showrev -p is: 381 thx (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

9. Shell Programming and Scripting

Outputting formatted Result log file from old 30000 lines result log<help required>

Well I have a 3000 lines result log file that contains all the machine data when it does the testing... It has 3 different section that i am intrsted in 1) starting with "20071126 11:11:11 Machine Header 1" 1000 lines... "End machine header 1" 2) starting with "20071126 12:12:12 Machine... (5 Replies)
Discussion started by: vikas.iet
5 Replies

10. Filesystems, Disks and Memory

Cannot adjust division

I have a doubt with an error message, and i want to be sure if this is a normal situation or not. Situation: I was formating and installing a SCSI 36Gb HD with UNIX SCO 5.05, the problem happens when is making the division and filesystem on disk 1, and the message error is "Exit value 139... (1 Reply)
Discussion started by: jav_v
1 Replies
Login or Register to Ask a Question