Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Posts
    6

    Unhappy Unanswered: awk and floating point numbers

    Hi all!

    I have read a line of text from a file with awk which is a floating point number. Now i want to multiply this float with 100, but it didnt work - the fractional part is missing:

    String: 0000018.50
    Float: 18,000000

    Whats the problem? I dont have any idea what i am making wrong....

    Thank you in advance
    Greetings!

  2. #2
    Join Date
    Sep 2003
    Posts
    7
    you might need to use bc -l

    * verify if you have bc on your unix box.

    do a man bc and learn how to implement it.




    Srikanth

  3. #3
    Join Date
    Nov 2003
    Posts
    6

    Arrow

    Thanks for this hint!

  4. #4
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    You could use the printf fuction to specify the precision...

    $ awk 'BEGIN {printf "%10.2f\n",0000018.50 * 18000000}'
    $ 333000000.00

    (You'll need to do something about the ',' in your float figure first though.)

Posting Permissions

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