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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

specify scale using dc - solaris 7

Status
Not open for further replies.

chughes

MIS
Aug 7, 2001
27
US
Hi folks - hopefully this is simple,
I'm writing some shell scripts to do some simple
math stuf for some of my users -
I'm using "dc" which is apparently an iteration
of "bc" . I need to set the scale (how many digits to the right of the decimal to display) when echoing a string
into the dc command ex: "echo 24.5 .5 * f | dc "
this command SHOULD give you an answer of 12.25 - dc is
truncating it to 12.2 or rounding it to 12.5.
if I feed it factors with the correct number of digits
ex: "echo 24.50 .5 * f| dc" then I get the desired output -
12.25 (dc having picked up from the input of 24.50 that I
want at least two digits on the ouput).
aaarrrrggghhhhh.
Chris
 
A quick read of the dc man page shows you need to set the "scale factor" to specify the number of decimal places to use. Try this ...

echo "2 k 24.5 .5 * f"|dc

The first bit of the dc string "2 k" sets the scale factor.

Greg.
 
Thanks!
i saw the scale thing in the man pages, but I could not figure out the syntax for the life of me....
thanks again!
Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top