Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org How to do arithmatic operation on floating number by using expr ???
 User Name Remember Me? Password
 Linux - Newbie This Linux forum is for members that are new to Linux. Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

 05-18-2009, 01:59 AM #1 raman.kumar LQ Newbie   Registered: May 2009 Posts: 1 Rep: How to do arithmatic operation on floating number by using expr ??? As i know that expr can not be used by decimal number....can anyone tell me that can i use expr and do arithmatic operation on decimal number ????
 05-18-2009, 02:35 AM #2 colucix LQ Guru   Registered: Sep 2003 Location: Bologna Distribution: CentOS 6.5 OpenSuSE 12.3 Posts: 10,509 Rep: You can use either bc or awk. Using bc you have to specify the scale that is the total number of decimal digits after the decimal point. For example: Code: ```\$ echo "scale=4; 3.4 / 2.0" | bc 1.7000 \$ echo "scale=9; 3.4 / 2.0" | bc 1.700000000``` In awk you can perform floating point arithmetic and print the result accordingly using printf: Code: ```\$ awk 'BEGIN{printf "%11.9f\n",3.4/2.0}' 1.700000000```
05-18-2009, 07:02 AM   #3
pixellany
LQ Veteran

Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep:
Quote:
 Originally Posted by raman.kumar As i know that expr can not be used by decimal number....can anyone tell me that can i use expr and do arithmatic operation on decimal number ????
Semantics:
"decimal number" means base 10. You mean floating point (not "floating")---or maybe "non-integer".

As you stated, "expr" does not do floating point. In fact, BASH does not do floating point. You need something like the suggestions from colucix.

Last edited by pixellany; 05-18-2009 at 07:03 AM.

 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 Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post lumix Linux - General 5 02-25-2009 05:31 PM ykwok Linux - General 4 06-17-2008 06:56 AM vijraj Programming 2 03-07-2007 04:17 PM max_rsr Linux - General 1 03-14-2005 01:43 AM max_rsr Linux - Newbie 1 03-12-2005 10:00 PM

LinuxQuestions.org

All times are GMT -5. The time now is 02:39 PM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -