bc
Brian K. White
brian at aljex.com
Fri Jan 20 12:05:51 PST 2006
----- Original Message -----
From: "John Esak" <john at valar.com>
To: "Fplist (E-mail)" <filepro-list at seaslug.org>
Sent: Friday, January 20, 2006 8:07 AM
Subject: OT: bc
> Does anyone know how to set "bc" to calculate the same way filePro does.
> With respoect to rounding that is.
>
> filePro will give 15.36 as the value for:
>
> aa(10,.2)="102.39" * ".15"
>
> and no matter what I do, bc gives 15.35 to the same mulitplication. I've
> set
> precision equal to 2, 4, 9, doesn't matter. If the precision goes up, it
> just goes up without rounding. If it goes lower down to 2, it truncates.
> Any
> way to have it not truncate but round?
>
> I like to check figures in filePro with bc and it's impossible. I've
> scanned
> the man page, of course, but didn't see anything about rounding.
>
> John
You could use printf.
use scale=3 or higher in bc to get 3 or more decimals
then use %8.2f in printf
# printf "%8.2f" `echo "scale=3;102.39 * .15" |bc`
or saner:
# n=`echo "scale=3;102.39 * .15" |bc`
# printf "%8.2f" $n
Brian K. White -- brian at aljex.com -- http://www.aljex.com/bkw/
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro BBx Linux SCO FreeBSD #callahans Satriani Filk!
More information about the Filepro-list
mailing list