Hello again.
I'm trying to use BC to calculate some numbers in a shell script.
I want to have the numbers rounded off to 1 decimal place.
for example:
initsize=1566720
zipsize=4733
I'm trying to get the ratio between them. the equation is:
(($initsize-$zipsize)/$initsize)*100
so... (3 Replies)
Hi,
Can any one help me in finding a solution for rounding off to 2 decimal places.
I am using the following code:
VAR1=.01292105263157894736
VAR2=`echo "scale=2; $VAR1 * 100" | bc -l`
The result I 'm getting is
1.29210526315789473600
But I need the output as 1.29
Thanks
Shash (2 Replies)
Hi All,
How we can handle decimals in (Float) in UNIX.
a=73
b=5
c=`expr a / b`
i am getting 14 but i need full 14.6 .
Can any one help me pls? (1 Reply)
I need to get 15% of the variable exer1 to be added to other exercises
so far, i've got
exer1=$1
aver=`expr $exer \* .15`
but i keep getting an error that an integer value was expected. Is there anyway around this? (1 Reply)
Hi,
I am trying to find if there is a way to convert regular decimal values to Paced decimal values. I tried to find a c program but I could get a Packed converted to regular decimal not the other way round.
If not unix please let me know if any other progrimming language I can use to do... (2 Replies)
Hi Guys,
I am generating a statistical report , below is the snippet of the code :
Now, $nSlices stands for the time duration,meaning,the statistics will be displayed for that particular time duration. Trouble is, for certain values of $totalTime (which is the end time - start time ), i... (9 Replies)
Hello,
I want to run a loop with non-integer values (which I know I can't) so I've created a loop of integers and divided it by 10. However, these values are always rounded down to 1 significant figure. How do I get the script to keep and use the decimal value?
My script is as follows
#... (1 Reply)
Hello...
I am new to unix and I am wondering if in a C-shell script , Are we supposed to use only whole numbers........ for example..if a program needs to calculate the average of some numbers........
@ avg = (($1 +$2 + $3)/3)) is returning a whole number.........How can a decimal be achieved... (1 Reply)
Dear Experts,
I'm trying to find a way to round a number but in this way:
14367.577 ---> 14000
I used the following to round the number to the closer integer:
echo $var|awk '{print int($1+0.5)}'
and also:
xargs printf "%1.0f"
However, they don't work for my above... (9 Replies)
Hi All,
I would like to do the following in the shell script
561.76 to 562
I tried using this echo 'scale=0; 749 * 75 /100 ' | bc
but just returned only 561
Please help me . I appreciate your help
Thanks
rajeevm (13 Replies)
Discussion started by: rajeevm
13 Replies
LEARN ABOUT SUNOS
fesetround
fegetround(3M) Mathematical Library Functions fegetround(3M)NAME
fegetround, fesetround - get and set current rounding direction
SYNOPSIS
cc [ flag... ] file... -lm [ library... ]
#include <fenv.h>
int fegetround(void);
int fesetround(int round);
DESCRIPTION
The fegetround function gets the current rounding direction.
The fesetround function establishes the rounding direction represented by its argument round. If the argument is not equal to the value of
a rounding direction macro, the rounding direction is not changed.
RETURN VALUES
The fegetround function returns the value of the rounding direction macro representing the current rounding direction, or a negative value
if there is no such rounding direction macro or the current rounding direction is not determinable.
The fesetround function returns a 0 value if and only if the requested rounding direction was established.
ERRORS
No errors are defined.
EXAMPLES
The following example saves, sets, and restores the rounding direction, reporting an error and aborting if setting the rounding direction
fails:
Example 1: Save, set, and restore the rounding direction.
#include <fenv.h>
#include <assert.h>
void f(int round_dir)
{
#pragma STDC FENV_ACCESS ON
int save_round;
int setround_ok;
save_round = fegetround();
setround_ok = fesetround(round_dir);
assert(setround_ok == 0);
/* ... */
fesetround(save_round);
/* ... */
}
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
|MT-Level |MT-Safe |
+-----------------------------+-----------------------------+
SEE ALSO fenv.h(3HEAD), attributes(5), standards(5)SunOS 5.10 1 Sep 2002 fegetround(3M)