Aug 5, 2002 #1 ooids Technical User May 2, 2001 21 US Hi! I have a very basic script: #!/bin/ksh A=0.5 B=0.5 C=$((A * B)) echo $C It returns 0 - How do i get it to output to 2dp / control the precision of the variables? Many Thanks
Hi! I have a very basic script: #!/bin/ksh A=0.5 B=0.5 C=$((A * B)) echo $C It returns 0 - How do i get it to output to 2dp / control the precision of the variables? Many Thanks
Aug 5, 2002 1 #2 vgersh99 Programmer Jul 27, 2000 2,146 US use 'bc' for floating point arithmetics vlad +---------------------------+ |#include<disclaimer.h> | +---------------------------+ Upvote 0 Downvote
use 'bc' for floating point arithmetics vlad +---------------------------+ |#include<disclaimer.h> | +---------------------------+
Aug 5, 2002 #3 dchoulette Programmer Jun 25, 2002 245 FR Yes, I suggest you use 'bc'. ... or 'dc' if you like more exotic RPN syntax. Upvote 0 Downvote
Aug 6, 2002 Thread starter #4 ooids Technical User May 2, 2001 21 US Thanks.. Would either of you be able to give me an example of using bc on my script? I'm a newbie, not used bc before.. Upvote 0 Downvote
Thanks.. Would either of you be able to give me an example of using bc on my script? I'm a newbie, not used bc before..
Aug 6, 2002 #5 dchoulette Programmer Jun 25, 2002 245 FR Code: C=$(echo "$A + $B" | bc); Upvote 0 Downvote
Aug 6, 2002 #6 vgersh99 Programmer Jul 27, 2000 2,146 US You might consider a finer precision for the floating point arirthmetics - say FOUR decimal points: C=$(echo "scale=4;${A} + ${B}" | bc); vlad +---------------------------+ |#include<disclaimer.h> | +---------------------------+ Upvote 0 Downvote
You might consider a finer precision for the floating point arirthmetics - say FOUR decimal points: C=$(echo "scale=4;${A} + ${B}" | bc); vlad +---------------------------+ |#include<disclaimer.h> | +---------------------------+
Aug 6, 2002 Thread starter #7 ooids Technical User May 2, 2001 21 US Thanks a lot for the help - just what i need... Upvote 0 Downvote