LinuxQuestions.org
Visit the LQ Articles and Editorials section
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
 
LinkBack Search this Thread
Old 08-10-2010, 10:23 AM   #1
MinuPriya
LQ Newbie
 
Registered: Aug 2010
Posts: 1

Rep: Reputation: 0
How to add decimal numbers in Linux


Can anyone specify the methods how to add decimal numbers in Linux
 
Old 08-10-2010, 10:27 AM   #2
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
In what context? You mean from the shell? If so, `bc` would be my first choice, although `awk` can also to arithmetic.
 
Old 08-10-2010, 10:52 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,390
Blog Entries: 2

Rep: Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900
Bash, and I assume any Korn oriented shell, cannot do floating point arithmetic. Almost any other programming environment can.
--- rod.
 
Old 08-10-2010, 09:29 PM   #4
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 718

Rep: Reputation: 72
Hi.

Many shells can do integer arithmetic.

Versions of ksh of at least ksh 93s+ can do floating point arithmetic, see man ksh.

Also zsh, see post # 11, http://www.linuxquestions.org/questi...script-336772/

Best wishes ... cheers, makyo
 
Old 08-10-2010, 09:59 PM   #5
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 239Reputation: 239Reputation: 239
to do calculation, use bc,dc , awk.
 
Old 08-11-2010, 12:31 AM   #6
b0uncer
Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Or fire up Python, which has those capabilities (and much more, start by importing things from math):
Code:
python
I find it simpler than running an awk command every time I need to calculate something (less typing).

Edit: or if you're fine with typing, you could just
Code:
python -c 'print .2+.8'

Last edited by b0uncer; 08-11-2010 at 12:34 AM.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Converting Binary Numbers To Decimal The Hard Way On Linux Or Unix LXer Syndicated Linux News 0 07-15-2008 07:11 AM
Format large numbers with commas at every thousandth decimal spot helpmhost Linux - General 8 10-01-2007 11:54 AM
bash scripting: loop over a file, replacing two decimal numbers frankie_DJ Programming 2 04-30-2007 04:04 PM
Decimal numbers in bash script variables? Massif Programming 3 11-07-2005 09:01 PM
How to use decimal numbers in in shell scripts a1ex_007 Programming 6 03-11-2005 09:05 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration