LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
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


Reply
  Search this Thread
Old 01-28-2012, 08:54 AM   #1
naushi
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Rep: Reputation: Disabled
fractions in linux


I am using fractions in my equations but it gives me an error. see below

let var1=3.4 does not work - var1=3 works

i also tried the bash calculator like


var1=`bc <<EOF
3.4+5.6
EOF
`
echo $var1

does not work gives me syntax error invalid arithmetic

any help will be appreciated
 
Old 01-28-2012, 09:56 AM   #2
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,476

Rep: Reputation: 189Reputation: 189
Bash does not natively support floating point math. You have to use a command line application called "bc" to do floating point math. Here's an article discussing the technique:

http://phoxis.org/2009/12/23/floatmathbash/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
bc and exponents containing decimals and fractions. Dogs Programming 6 03-12-2013 05:27 PM
cannot add fractions in loop using bc in a script? sonu kumar Linux - Newbie 5 02-11-2010 06:24 PM
how to convert binary fractions to decimal jabka Programming 12 12-16-2006 07:05 PM
how to work with fractions in c ? (help neded); jabka Programming 7 11-20-2006 04:06 PM


All times are GMT -5. The time now is 10:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration