Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    84

    Unanswered: Computing percentage

    I wish to find % used using shell variables
    and am using the following

    USED=`expr $1\* 100 / $2`;

    But this does not take decimal portion of $1 .
    How to resolve?

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    use 'bc' instead of 'expr'

    USED=`echo "scale=2;$1 * 100 / $2" | bc"

    $1=10.2
    $2=244
    $USED=4.18
    Jean-Pierre.

  3. #3
    Join Date
    Jan 2004
    Posts
    84
    This doesn't work.. Some syntax problem?

  4. #4
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Sorry, there is a missing ` :

    USED=`echo "scale=2;$1 * 100 / $2" | bc"`
    Jean-Pierre.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •