Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Decimal points

Status
Not open for further replies.

MED

Programmer
Joined
Aug 13, 2001
Messages
4
Location
GB
Help! I'm having problems adding numbers with decimal points. I need an answer with decimal points but it keeps rounding down.

This is the line that I'm using -
TOTAL=$((TOTAL+$AMT))

Can anyone point me in the right direction?
Thanks!

 
shell arithmetic is integer ONLY:
TOTAL=$(echo "${TOTAL}+${AMT}" | bc) vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
MED:

Vlad's right about ksh arithmetic being integer only. That's ksh88. However, the ksh93 version does support decimal arithmetic:

This works on my solaris 7 box:

#!/usr/dt/bin/dtksh

let sum=$((5.2+6.3))
printf &quot;%f\n&quot; $sum
# end script

The dtksh shell is 93 compliant.

Regards,

Ed

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top