View the Most Wanted LQ Wiki articles.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org Bourne and Decimals?
 User Name Remember Me? Password
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 05-06-2008, 10:02 PM #1 kdyzsa LQ Newbie   Registered: May 2008 Posts: 7 Rep: 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?
 05-06-2008, 10:30 PM #2 eggixyz Member   Registered: Apr 2008 Posts: 310 Rep: 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
 05-07-2008, 12:13 AM #3 kdyzsa LQ Newbie   Registered: May 2008 Posts: 7 Original Poster Rep: 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?
 05-07-2008, 12:37 AM #4 chrism01 Guru   Registered: Aug 2004 Location: Sydney Distribution: Centos 6.6, Centos 5.10 Posts: 16,401 Rep: Try bc echo 70*15|bc 1050 echo 70*.15|bc 10.50 http://www.faqs.org/docs/abs/HTML/mathc.html
 05-07-2008, 01:16 AM #5 kdyzsa LQ Newbie   Registered: May 2008 Posts: 7 Original Poster Rep: 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