Bourne and Decimals?
I'm suppose to use the Bourne Shell
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? |
Hey there,
The straight Bourne shell doesn't have any support for floating point decimals. The usual work-around is to (on a hundredth, like .15 or .87, etc) move the decimal point over two right and do the math, then move it back over 2 left. Chek this link out for a script that deals with floating point in ksh (but also works in Bourne - the arithmetic, anyway): http://linuxshellaccount.blogspot.co...metic-and.html Hope that helps, Mike |
Hm..
Well.. unfortunately the site can't be opened since it's blocked here.
So I thought about that idea so I'll cut it. ex. exer=70 aver=`expr $exer \* 15` the sample output would be aver =1050, but unfortunately cut doesn't work with integers i think since i tried first=`echo $aver | cut -c1-2` and the output i got was "an integer value was expected" Any help guys? |
|
Thanks
Thanks a lot for the bc tip. It's working smoothly now. I was stuck at that problem a while ago. Now I'll to finish my script by the end of the day. Thanks again ;)
|
All times are GMT -5. The time now is 05:50 PM. |