OT: bc

Brian K. White brian at aljex.com
Fri Jan 20 13:54:11 PST 2006


----- Original Message ----- 
From: "Bob Stockler" <bob at trebor.iglou.com>
To: <filepro-list at lists.celestial.com>
Sent: Friday, January 20, 2006 4:05 PM
Subject: Re: OT: bc


> Brian K. White wrote (on Fri, Jan 20, 2006 at 03:38:38PM -0500):
>
> | From: "Bob Stockler" <bob at trebor.iglou.com>
> |
> | >John Esak wrote (on Fri, Jan 20, 2006 at 08:07:31AM -0500):
> | >
> | >| 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.
> | >
> | >Would you settle for using AWK?  If so, create this little
> | >script and make it executable:
> | >
> | > #!/bin/awk -f
> | > { x = $1 * $2 ; printf("%6.2f\n", x) }
> | >
> | >Then try:  echo "102.39 .15" | scriptname
> | >
> | >Edit the "6" in the printf argument to be whatever number
> | >of digits you need to the left of the decimal point.
> |
> | printf is available outside of awk right at the shell.
> | not just in ksh as a builtin either, it's a stand alone binary.
>
> I don't find printf as a ksh builtin on SCO OSR6, so why
> call two binaries (bc and printf) to do what one will do?

So that the input can be anything bc accepts including large formula with 
multiple/nested parens etc...

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