Re: how to calculate fractions with let?
From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 03/21/05
- Next message: samuels_at_red.seas.upenn.edu: "Re: how to calculate fractions with let?"
- Previous message: samuels_at_red.seas.upenn.edu: "how to calculate fractions with let?"
- In reply to: samuels_at_red.seas.upenn.edu: "how to calculate fractions with let?"
- Next in thread: samuels_at_red.seas.upenn.edu: "Re: how to calculate fractions with let?"
- Reply: samuels_at_red.seas.upenn.edu: "Re: how to calculate fractions with let?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 21 Mar 2005 17:44:47 GMT
On Mon, 21 Mar 2005 at 17:37 GMT, samuels@red.seas.upenn.edu () wrote:
> hi,
> for the arithmetic expression 7/3, what unix function/command will
> show me the correct value of 2.33 and not just 2 like let?
Most shells do not support fractional arithmetic (ksh93 is an
exception).
You need to use an external command such as awk or bc.
For example, I use this function:
calc()
{
awk 'BEGIN { OFMT="%f"; print '"$*"'; exit}'
}
Once it's defined you can use:
$ calc 7/3
2.333333
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
===================================================================
My code (if any) in this post is copyright 2005, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
- Next message: samuels_at_red.seas.upenn.edu: "Re: how to calculate fractions with let?"
- Previous message: samuels_at_red.seas.upenn.edu: "how to calculate fractions with let?"
- In reply to: samuels_at_red.seas.upenn.edu: "how to calculate fractions with let?"
- Next in thread: samuels_at_red.seas.upenn.edu: "Re: how to calculate fractions with let?"
- Reply: samuels_at_red.seas.upenn.edu: "Re: how to calculate fractions with let?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|