Review your favorite Linux distribution.
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 08-10-2010, 11:23 AM   #1
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, 11:27 AM   #2
LQ Guru
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
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, 11:52 AM   #3
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

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

Rep: Reputation: 75

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,

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

Rep: Reputation: 244Reputation: 244Reputation: 244
to do calculation, use bc,dc , awk.
Old 08-11-2010, 01:31 AM   #6
LQ 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):
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
python -c 'print .2+.8'

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


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
LXer: Converting Binary Numbers To Decimal The Hard Way On Linux Or Unix LXer Syndicated Linux News 0 07-15-2008 08:11 AM
Format large numbers with commas at every thousandth decimal spot helpmhost Linux - General 8 10-01-2007 12:54 PM
bash scripting: loop over a file, replacing two decimal numbers frankie_DJ Programming 2 04-30-2007 05:04 PM
Decimal numbers in bash script variables? Massif Programming 3 11-07-2005 10:01 PM
How to use decimal numbers in in shell scripts a1ex_007 Programming 6 03-11-2005 10:05 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:17 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration