If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > awk and floating point numbers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-16-03, 10:21
coredump coredump is offline
Registered User
 
Join Date: Nov 2003
Posts: 6
Unhappy 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!
Reply With Quote
  #2 (permalink)  
Old 12-16-03, 16:59
skrishnaswamy skrishnaswamy is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 12-17-03, 08:01
coredump coredump is offline
Registered User
 
Join Date: Nov 2003
Posts: 6
Arrow

Thanks for this hint!
Reply With Quote
  #4 (permalink)  
Old 12-17-03, 09:24
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
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.)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On