Sponsored Content
Top Forums UNIX for Beginners Questions & Answers awk division without rounding Post 303046082 by drl on Thursday 23rd of April 2020 09:24:01 AM
Old 04-23-2020
Hi.

This might possibly be done for the range of numbers noted by parsing the numbers, inserting 2 zeros, and so avoiding any arithmetic whatsoever -- just a thought ... cheers, drl
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

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 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 (3 Replies)
Discussion started by: Indalecio
3 Replies

2. Shell Programming and Scripting

Rounding issue with awk

Hi Friends, I am trying to round following number. 0.07435000 echo "0.07435000"|awk '{printf "%s\n",$1*100}'|awk '{printf "%.2f\n",$1}' It returns: 7.435 It should return: 7.44 Any suggestion please? Thanks, Prashant (2 Replies)
Discussion started by: ppat7046
2 Replies

3. Shell Programming and Scripting

awk Division and modulus

I need to read the file divide 3 column with 2nd and run a modulus of 10 and check whether the remainder is zero or not if not print the entire line. cat filename | awk '{ if ($3 / $2 % 10 != 0) print $0}' Whats wrong with it ? (4 Replies)
Discussion started by: dinjo_jo
4 Replies

4. Shell Programming and Scripting

AWK rounding up numbers

Hi, I have managed to round up numbers by using the following command: echo "5.54" | awk '{printf "%.0f\n", $1}' result 6 How can I round up all the numbers in a column in a file and print the lines with the new calculated totals? Thanks, (3 Replies)
Discussion started by: keenboy100
3 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. Shell Programming and Scripting

awk, floating point and rounding

I had a person bring an interesting problem to me that appears to involve some sort of rounding inside awk. I've verified this with awk and nawk on Solaris as well as with gawk 3.1.5 on a Linux box. The original code fragment he brought me was thus: for (index=0; index < 1; index=index+.1) ... (4 Replies)
Discussion started by: mmyer2
4 Replies

7. Shell Programming and Scripting

awk & division

vmstat|awk '{print $3}'|tail -1 returns 6250511, but what I need is 24416, which is 6250511 divided by 256. Please advise. Thank you so much (2 Replies)
Discussion started by: Daniel Gate
2 Replies

8. Shell Programming and Scripting

awk calculation automatically rounding off the output

I have some calculation in my script which is similar to the below example . I find that sometimes when using large decimal digits, the output gets automatically rounded off and it is affecting the program. I am not able to understand what is happening here.. awk '{ a=6.32498922 a1=6.324... (5 Replies)
Discussion started by: wanderingmind16
5 Replies

9. Shell Programming and Scripting

awk - Division with condition

Hi Friends, I have an input file like this cat input chr1 100 200 1 2 chr1 120 130 na 1 chr1 140 160 1 na chr1 170 180 na na chr1 190 220 0 0 chr1 220 230 nd 1 chr2 330 400 1 nd chr2 410 450 nd nd chr3 500 700 1 1 I want to calculate the division of 4th and 5th columns. But, if... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

10. Shell Programming and Scripting

[awk] rounding a float number?

Heyas Trying to calculate the total size of a file by reading its bitrate. Code snippet: fs_expected() { # # Returns the expected filesize in bytes # pr_str() { ff=$(cat $TMP.info) d="${ff#*bitrate: }" echo "${d%%,*}" | $AWK '{print $1}' | head -n 1 } t_BYTERATE=$((... (9 Replies)
Discussion started by: sea
9 Replies
float.h(3HEAD)							      Headers							    float.h(3HEAD)

NAME
float.h, float - floating types SYNOPSIS
#include <float.h> DESCRIPTION
The characteristics of floating types are defined in terms of a model that describes a representation of floating-point numbers and values that provide information about an implementation's floating-point arithmetic. The following parameters are used to define the model for each floating-point type: s sign (+-1) b base or radix of exponent representation (an integer >1) e exponent (an integer between a minimum e(min) and a maximum e(max)) p precision (the number of base-b digits in the significand) f(k) non-negative integers less than b (the significand digits) In addition to normalized floating-point numbers (f(1)>0 if x!=0), floating types might be able to contain other kinds of floating-point numbers, such as subnormal floating-point numbers (x!=0, e=e(min), f(1)=0) and unnormalized floating-point numbers (x!=0, e=e(min), f(1)=0), and values that are not floating-point numbers, such as infinities and NaNs. A NaN is an encoding signifying Not-a-Number. A quiet NaN propagates through almost every arithmetic operation without raising a floating-point exception; a signaling NaN generally raises a floating-point exception when occurring as an arithmetic operand. The accuracy of the library functions in math.h(3HEAD) and complex.h(3HEAD) that return floating-point results is defined on the libm(3LIB) manual page. All integer values in the <float.h> header, except FLT_ROUNDS, are constant expressions suitable for use in #if preprocessing directives; all floating values are constant expressions. All except DECIMAL_DIG, FLT_EVAL_METHOD, FLT_RADIX, and FLT_ROUNDS have separate names for all three floating-point types. The floating-point model representation is provided for all values except FLT_EVAL_METHOD and FLT_ROUNDS. The rounding mode for floating-point addition is characterized by the value of FLT_ROUNDS: -1 Indeterminable. 0 Toward zero. 1 To nearest. 2 Toward positive infinity. 3 Toward negative infinity. The values of operations with floating operands and values subject to the usual arithmetic conversions and of floating constants are evalu- ated to a format whose range and precision might be greater than required by the type. The use of evaluation formats is characterized by the architecture-dependent value of FLT_EVAL_METHOD: -1 Indeterminable. 0 Evaluate all operations and constants just to the range and precision of the type. 1 Evaluate operations and constants of type float and double to the range and precision of the double type; evaluate long double opera- tions and constants to the range and precision of the long double type. 2 Evaluate all operations and constants to the range and precision of the long double type. The values given in the following list are defined as constants. o Radix of exponent representation, b. FLT_RADIX o Number of base-FLT_RADIX digits in the floating-point significand, p. FLT_MANT_DIG DBL_MANT_DIG LDBL_MANT_DIG o Number of decimal digits, n, such that any floating-point number in the widest supported floating type with p(max) radix b dig- its can be rounded to a floating-point number with n decimal digits and back again without change to the value. DECIMAL_DIG o Number of decimal digits, q, such that any floating-point number with q decimal digits can be rounded into a floating-point num- ber with p radix b digits and back again without change to the q decimal digits. FLT_DIG DBL_DIG LDBL_DIG o Minimum negative integer such that FLT_RADIX raised to that power minus 1 is a normalized floating-point number, e(min). FLT_MIN_EXP DBL_MIN_EXP LDBL_MIN_EXP o Minimum negative integer such that 10 raised to that power is in the range of normalized floating-point numbers. FLT_MIN_10_EXP DBL_MIN_10_EXP LDBL_MIN_10_EXP o Maximum integer such that FLT_RADIX raised to that power minus 1 is a representable finite floating-point number, e(max). FLT_MAX_EXP DBL_MAX_EXP LDBL_MAX_EXP o Maximum integer such that 10 raised to that power is in the range of representable finite floating-point numbers. FLT_MAX_10_EXP DBL_MAX_10_EXP LDBL_MAX_10_EXP The values given in the following list are defined as constant expressions with values that are greater than or equal to those shown: o Maximum representable finite floating-point number. FLT_MAX DBL_MAX LDBL_MAX The values given in the following list are defined as constant expressions with implementation-defined (positive) values that are less than or equal to those shown: o The difference between 1 and the least value greater than 1 that is representable in the given floating-point type, b^1 - p. FLT_EPSILON DBL_EPSILON LDBL_EPSILON o Minimum normalized positive floating-point number, b^e(min)^-1. FLT_MIN DBL_MIN LDBL_MIN ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
complex.h(3HEAD), math.h(3HEAD), attributes(5), standards(5) SunOS 5.11 17 Dec 2003 float.h(3HEAD)
All times are GMT -4. The time now is 04:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy