Computing.Net > Forums > Unix > multiply decimals

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

multiply decimals

Reply to Message Icon

Name: Robert Pearson
Date: August 9, 2003 at 17:32:14 Pacific
OS: Mandrake 9.1
CPU/Ram: p3 500 / 128mb
Comment:

This has been driving me nuts for a few days now. I can't figure out how to multiply decimals in a korn script.

What I have that works...
time=$(($1*2))
echo $time

What I have that doesn't work...
time=$(($1*1.7))
echo $time

Thanks in advanced,
FourSKY



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: August 9, 2003 at 18:09:14 Pacific
Reply:

Someone asked about this recently and the answer was to use 'expr'. Most (if any) shells don't support fractional numbers.

I suggest looking at 'man expr'


0

Response Number 2
Name: nails
Date: August 9, 2003 at 21:15:13 Pacific
Reply:

Robert:

The latest version of ksh, ksh93, supports float arithmetic. Check out http://www.kornshell.com

In addition to expr, you can also you other external tools such as awk or bc:

x=5
y=$(bc MSG
scale=1
$x * 1.7
MSG
)
# the above is a unix here document, so you need two less than signs between bc & MSG.

echo $y

Regards,


Nails


0

Response Number 3
Name: Robert Pearson
Date: August 10, 2003 at 06:48:43 Pacific
Reply:

I had to install BC, but it works like a champ. Thanks Nails!

FourSKY


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


file permission problem Penggy (ifconfig, route :...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: multiply decimals

Hex to Decimal www.computing.net/answers/unix/hex-to-decimal/4017.html

convert decimal in hex www.computing.net/answers/unix/convert-decimal-in-hex/5346.html

sum or multiply data in files www.computing.net/answers/unix/sum-or-multiply-data-in-files/3797.html