how do arithmetic operations with floating point no in shell script - Linux

This is a discussion on how do arithmetic operations with floating point no in shell script - Linux ; 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 ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: how do arithmetic operations with floating point no in shell script

  1. how do arithmetic operations with floating point no in shell script

    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

  2. Re: how do arithmetic operations with floating point no in shell script

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1
    NotDashEscaped: You need GnuPG to verify this message

    In comp.os.linux.misc karthikeyan 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-----

  3. Re: how do arithmetic operations with floating point no in shellscript

    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




  4. Re: how do arithmetic operations with floating point no in shell script

    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 wrote in message news:...
    > 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


  5. Re: how do arithmetic operations with floating point no in shell script

    thegreatkarthik@yahoo.co.in (karthikeyan) wrote in message news:...
    > 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.

  6. Re: how do arithmetic operations with floating point no in shell script

    In comp.os.linux.misc karthikeyan 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

  7. Re: how do arithmetic operations with floating point no in shell script

    robertharvey@my-deja.com (Robert E A Harvey) writes:
    >thegreatkarthik@yahoo.co.in (karthikeyan) wrote in message news:...
    >> 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

    scott

  8. Re: how do arithmetic operations with floating point no in shell script

    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 sysengr

+ Reply to Thread