Arithmetic in Korn Shell

Arithmetic in Korn Shell

Post by Eric Gorel » Thu, 19 Nov 1998 04:00:00



Is it possible to do simple arithmetic in Korn Shell with decimal
numbers?
I'm trying to add 0.1 to a number such as 1.3; is this possible?
 
 
 

Arithmetic in Korn Shell

Post by Al Shark » Thu, 19 Nov 1998 04:00:00



> Is it possible to do simple arithmetic in Korn Shell with decimal
> numbers?
> I'm trying to add 0.1 to a number such as 1.3; is this possible?

echo "0.1 1.3+pq" | dc

 
 
 

Arithmetic in Korn Shell

Post by Jim Mellande » Thu, 19 Nov 1998 04:00:00




> > Is it possible to do simple arithmetic in Korn Shell with decimal
> > numbers?
> > I'm trying to add 0.1 to a number such as 1.3; is this possible?

> echo "0.1 1.3+pq" | dc

Or, if you're not a fan of RPN, you can use bc

echo "0.1+1.3"|bc

 
 
 

Arithmetic in Korn Shell

Post by brian hile » Thu, 19 Nov 1998 04:00:00



> ...

"Decimal" numbers? Do you not mean "floating point notation"?

You did no mention the ksh version, so the answer is: yes, for ksh93.
The answer for ksh88 is still yes, however, the fractional part of the
floating point number will be truncated.

-Brian

 
 
 

Arithmetic in Korn Shell

Post by Dan Merc » Thu, 19 Nov 1998 04:00:00






>> > Is it possible to do simple arithmetic in Korn Shell with decimal
>> > numbers?
>> > I'm trying to add 0.1 to a number such as 1.3; is this possible?

>> echo "0.1 1.3+pq" | dc

> Or, if you're not a fan of RPN, you can use bc

> echo "0.1+1.3"|bc

And if you have a lot of computation to do,  I would suggest
starting bc as a co_process:

bc |&

print -p "0.1+1.3"
read -p ans

...

print -p "quit"

Opinions expressed herein are my own and may not represent those of my employer.

 
 
 

Arithmetic in Korn Shell

Post by DFRusse » Fri, 20 Nov 1998 04:00:00


|> Is it possible to do simple arithmetic in Korn Shell with decimal
|> numbers?
|> I'm trying to add 0.1 to a number such as 1.3; is this possible?
|>

A=0.1
B=1.3
let C=A+B
echo $C

--
Views expressed are personal and not necessarily shared by my employer.

 
 
 

Arithmetic in Korn Shell

Post by Peter Samuels » Tue, 24 Nov 1998 04:00:00



Quote:> > Is it possible to do simple arithmetic in Korn Shell with decimal
> > numbers?  I'm trying to add 0.1 to a number such as 1.3; is this
> > possible?


Quote:> A=0.1
> B=1.3
> let C=A+B
> echo $C

...if you happen to be using ksh93.

--
Peter Samuelson
<sampo.creighton.edu!psamuels>

 
 
 

Arithmetic in Korn Shell

Post by DrSilve » Tue, 24 Nov 1998 04:00:00




> > > Is it possible to do simple arithmetic in Korn Shell with decimal
> > > numbers?  I'm trying to add 0.1 to a number such as 1.3; is this
> > > possible?

> > A=0.1
> > B=1.3
> > let C=A+B
> > echo $C

> ...if you happen to be using ksh93.

> --
> Peter Samuelson
> <sampo.creighton.edu!psamuels>

If not,

A=0.1
B=1.3

C=`bc << EOF
$A + $B
EOF`

echo $C