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..
prints:
Where is the decimals points in "d" . And if it got rounded off, why is the decimals appearing in "result1"
Could you help me understand what really is happening ? How can i make sure that the decimals does not get rounded off automatically?
Last edited by zaxxon; 08-07-2012 at 07:39 AM..
Reason: code tags
Hallo all,
I have a script which creates an output ... see below:
root@a7germ:/tmp/pax > cat 20061117.txt
523.047
521.273
521.034
517.367
516.553
517.793
513.114
513.940
I would like to use awk to calculate the (a)total sum of the numbers (b) The average of the numbers.
Please... (4 Replies)
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)
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)
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)
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)
Hi guys,
could someone throw some light on the following behaviour of printf (I'll start with info about the system and the tool/shell/interpreter versions)?:
$ uname -a
Linux linux-86if.site 3.1.0-1.2-desktop #1 SMP PREEMPT Thu Nov 3 14:45:45 UTC 2011 (187dde0) x86_64 x86_64 x86_64... (9 Replies)
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)
I am trying to run the awk below. My question is when I split the input, then run anotherawk to perform a calculation using that splitas the input there are no issues. When I try to combine them the output is not correct, is the split not working or did I do it wrong? Thank you :).
input
... (8 Replies)
The awk below is close but I can't seem to fix it to produce the desired output. Thank you :).
current awk with output
awk '{c1++; c2+=($2)}
END{for (e in c1) print e, c1, c2}' input
EFCAB5 2 50
USH2A 2 19
desired... (8 Replies)
In the below awk, I am trying to calculate percent for a given id. It is very close the problem is when the # being used in the calculation is zero. I am not sure how to code this condition into the awk as it happens frequently. The portion in italics was an attempt but that lead to an error. Thank... (13 Replies)
Discussion started by: cmccabe
13 Replies
LEARN ABOUT DEBIAN
concalc
CONCALC(1) User Commands CONCALC(1)NAME
concalc - console calculator
SYNOPSIS
concalc [options] "expression"
concalc -m script "path"
DESCRIPTION
concalc calculates the given input term and returns the result as text. Please use will have problems with the shell interpretor. If you
give concalc more than one expression, all expression will be put together.
CALCULATION SYNTAX
standard calculations
2*(3+4/9)^3
standard operations
+ - * / ^ % sin cos tan asin acos atan sinh cosh tanh asinh acosh atanh ln log & | ! && || ~ >> << x rnd sqrt curt root integ d/dx
sqare root and cubic root
sqrt12 curt8
trigonometric functions and logarithms
sin3.64+ln5
other roots
fourth root of nine: 4root9
differential calculation
differential calculation of 2x^2-3x+3 at x=9: d/dx(2x^2-3x+3,9)
integration
integration of sinx+cosx between -1 and 3.2: integ(sinx+cosx,-1,3.2)
set variables
save the result of a calculation in variable A: 12*45/2->A
recall variables
multiply the saved value with 2: A*2
use last result
The last result is saved in the answer memory: ans+1
CONSTANTS
e euler constant
pi pi; example: sin(pi/2)
NUMBERS
standard
12.34
with exponent
12.23e-5
complex
12i-5
OPTIONS -o, --output [output length]
The argument is a number between 2 and the maximal possible output length (normally 18).
-m, --mode [calculator mode]
The mode can be std (default, normal scientific calculatons), base (for logic functions and base-n calculatons) or script (for exe-
cuting scripts). In scripting mode, the last argument must be the path to the script file.
-c, --complex
This option enables complex numbers for the calculation. They are switched off by default.
-b, --base [calculator base]
The argument must be one of hex (hexadecimal), dec (decimal, default), oct (octal) and bin (binary). This option can only be used
when -m base is set.
-a, --angle [angle type]
The argument must be one of deg (degrees), rad (radiant), gra (grade).
-v, --version
Output the version of Concalc.
-h, --help
Outputs a short help.
SCRIPTING
The script interpreter of calc uses a C-like programming syntax. The following command are supported.
if expression
if(condition)
command for condition true;
else command for condition false;
while loop
while(condition)
command that is run while condition is true;
for loop
for(initialisation; condition; count-command)
command that is run while condition is true;
print command
print( output to print out );
getline command
getline; // read a text line from stdin and returns this text
getkey command
getkey; // return the key pressed by the user
// blocks until the user presses any key
keystate command
keystate; // returns the key pressed by the user or 0 if no key was pressed
// nonblocking
sleep command
sleep( time in microseconds ); //Script is stops for the given time
compare operators
==, != equal, unequal
>=, <=, >, < greather or equal, less or equal, greather, less
set operators
-> calculator set operator
= C-like set operator
type converting
(float) floating point value
(int) integer value
(string) text value
(bool) boolean value
BUGS
No bugs known!
If you find one, please report it by e-mail to the author.
AUTHOR
Rainer Strobel <rainer1223@users.sourceforge.net>
SEE ALSO
http://extcalc-linux.sourceforge.net
Linux APRIL 2007 CONCALC(1)