Sponsored Content
Top Forums Shell Programming and Scripting how to get exact result in my division Post 302160838 by user_prady on Tuesday 22nd of January 2008 11:24:13 PM
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..
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
quantized64(3M) 														   quantized64(3M)

NAME
quantized64(), quantized128(), quantized32() - decimal quantize functions SYNOPSIS
DESCRIPTION
The function sets the exponent of x to the exponent of y, while attempting to keep the value the same. If the exponent is being increased, the value is correctly rounded according to the current (decimal) rounding mode. is useful for rounding to a specified number of decimal places. For example, will round x to four places to the right of the decimal point (provided the has enough digits to do so). is a version of it takes arguments and returns a result. is a version of it takes arguments and returns a result. These math functions are supported for HP-UX 11i Version 3 September 2008 Update and forward. USAGE
To use any of these functions, compile with the option. Make sure your program defines and then includes Link in the math library by specifying or on the linking command line. For more information, see the at the following site: RETURN VALUE
If the exponent of x is being increased and rounding produces a result whose numerical value is different from x, then raises the inexact exception. If the exponent of x is being decreased and the of the result has more digits than the type would allow, returns NaN and raises the invalid exception. If one or both arguments are NaN, then returns NaN. Otherwise, if only one argument returns NaN and raises the invalid exception. If both arguments returns x. ERRORS
No errors are defined. SEE ALSO
quantexpd64(3M), samequantumd64(3M), math(5). STANDARDS CONFORMANCE
These functions conform to ISO/IEC TR 24732, "Extension for the programming language C to support decimal floating-point arithmetic". HP Integrity Server Only quantized64(3M)
All times are GMT -4. The time now is 02:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy