Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 01-28-2012, 07:54 AM   #1
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
echo $var1

does not work gives me syntax error invalid arithmetic

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

Rep: Reputation: 270Reputation: 270Reputation: 270
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:


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 04:27 PM
cannot add fractions in loop using bc in a script? sonu kumar Linux - Newbie 5 02-11-2010 05:24 PM
how to convert binary fractions to decimal jabka Programming 12 12-16-2006 06:05 PM
how to work with fractions in c ? (help neded); jabka Programming 7 11-20-2006 03:06 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:53 AM.

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