This is a discussion on how do arithmetic operations with floating point no in shell script within the Linux Administration forums, part of the Linux Forums category; sir, how do arithmetic operations with floating point number shell script program expr only provide solution for whole numbers I ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
sir,
how do arithmetic operations with floating point number shell script program expr only provide solution for whole numbers I want to add floating no moreover even the ulility like "bc" - calculator adds only whole numbers Is there any utility to operate on floating point no Help me thks in adv |
|
|||
|
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1 NotDashEscaped: You need GnuPG to verify this message In comp.os.linux.misc karthikeyan <thegreatkarthik@yahoo.co.in> suggested: > sir, > how do arithmetic operations with floating point number shell script program > expr only provide solution for whole numbers > I want to add floating no > moreover even the ulility like "bc" - calculator adds only whole numbers Works for me: echo "scale=2; 2.51+2.51" | bc 5.02 Good luck -- Michael Heiming (GPG-Key ID: 0xEDD27B94) mail: echo zvpunry@urvzvat.qr | perl -pe 'y/a-z/n-za-m/' -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFA98ahAkPEju3Se5QRAmmrAJ9awmuvxWh9jEIj6cN13x +uY1qSKgCfZxWH mseBh9BOlw4hdNnkhchDPlc= =hQic -----END PGP SIGNATURE----- |
|
|||
|
karthikeyan wrote:
> sir, > how do arithmetic operations with floating point number shell script program > expr only provide solution for whole numbers > I want to add floating no > moreover even the ulility like "bc" - calculator adds only whole numbers > Is there any utility to operate on floating point no bc should understand decimal numbers $ echo "1.2 - 3.4 " | bc -2.3 > Help me > thks in adv You may browse to http://www.futuredesktop.org/RedHat9-apt-get.html and search for "Math" on that page. // moma http://www.futuredesktop.org :: The most relevant links at the top |
|
|||
|
sir,
Thks a lot for your valuable help. Is there any possible option to go for floating point calculation in "expr" help me Thks in adv again moma <moma@example.net> wrote in message news:<apQJc.3735$v04.53421@news2.e.nsc.no>... > karthikeyan wrote: > > sir, > > how do arithmetic operations with floating point number shell script program > > expr only provide solution for whole numbers > > I want to add floating no > > moreover even the ulility like "bc" - calculator adds only whole numbers > > Is there any utility to operate on floating point no > > bc should understand decimal numbers > $ echo "1.2 - 3.4 " | bc > -2.3 > > > > Help me > > thks in adv > > You may browse to > http://www.futuredesktop.org/RedHat9-apt-get.html > and search for "Math" on that page. > > > // moma > http://www.futuredesktop.org :: The most relevant links at the top |
|
|||
|
thegreatkarthik@yahoo.co.in (karthikeyan) wrote in message news:<ecaee7af.0407170405.6a3bc843@posting.google. com>...
> sir, > Thks a lot for your valuable help. > Is there any possible option to go for floating point calculation in "expr" > help me > Thks in adv again If you want better maths than the shell can handle, consider using perl instead. |
|
|||
|
In comp.os.linux.misc karthikeyan <thegreatkarthik@yahoo.co.in> wrote:
> how do arithmetic operations with floating point number shell script program > expr only provide solution for whole numbers > I want to add floating no > moreover even the ulility like "bc" - calculator adds only whole numbers > Is there any utility to operate on floating point no Hi, awk will do simple arithmetic with floating point numbers. For example: robpc2>echo 1.1 2.2 | awk ' { printf "%f\n", $1 + $2 } ' 3.300000 Cheers, Rob Komar |
|
|||
|
robertharvey@my-deja.com (Robert E A Harvey) writes:
>thegreatkarthik@yahoo.co.in (karthikeyan) wrote in message news:<ecaee7af.0407170405.6a3bc843@posting.google. com>... >> sir, >> Thks a lot for your valuable help. >> Is there any possible option to go for floating point calculation in "expr" >> help me >> Thks in adv again > >If you want better maths than the shell can handle, consider using perl instead. ksh93 handles floating point calculations natively using the let or (( )) expression evaluation functionality. Available from <http://www.kornshell.com/> scott |
|
|||
|
thegreatkarthik@yahoo.co.in (karthikeyan) writes:
> sir, > how do arithmetic operations with floating point number shell script program > expr only provide solution for whole numbers > I want to add floating no > moreover even the ulility like "bc" - calculator adds only whole > numbers You need to use an external program. bc and dc are fine for really simple stuff. awk (gawk) is good for medium level file scan - simple stuff on command line, more complex things by script file. octave is good for matrix math and can be operated by script files. Other viable options include perl and clisp. > Is there any utility to operate on floating point no > Help me > thks in adv -- Johan KULLSTAM <kullstj-nn@comcast.net> sysengr |