LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-30-2014, 12:49 AM   #1
ivahbee
LQ Newbie
 
Registered: Oct 2014
Location: i live in one of the isles in the South Pacific region.
Posts: 4

Rep: Reputation: Disabled
how to multiply an integer with a decimal using shell scripting?


I cant seem to get an answer when i multiply an integer with a decimal.

e.g a=5.14
b=7

answer=`expr $a \* $b`
echo "answer = $answer"

When i run it on the terminal, it keeps saying
expr: non-integer argument
answer=


Can someone help me?
Tell me where im going wrong?
 
Old 10-30-2014, 03:35 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
install bc if it isn't installed already.
read its documentation:
Code:
man bc
 
1 members found this post helpful.
Old 10-30-2014, 03:38 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,830

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
the shell itself (bash) cannot handle decimals, you need to use something else to do that: bc, perl, awk, dc just to name a few.
 
1 members found this post helpful.
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
why omit unsigned int in unsuffixed decimal integer constant? password636 Programming 1 11-15-2011 11:00 PM
bash scripting: converting integer to decimal Hawkallica Programming 7 10-01-2011 04:16 AM
bash scripting and integer variables. stf92 Linux - Software 1 06-06-2010 06:30 PM
bash scripting: loop over a file, replacing two decimal numbers frankie_DJ Programming 2 04-30-2007 04:04 PM
How to use decimal numbers in in shell scripts a1ex_007 Programming 6 03-11-2005 09:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:36 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
Open Source Consulting | Domain Registration