Addition of floating numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Addition of floating numbers
# 1  
Old 11-13-2009
Addition of floating numbers

Hi,
i want to add two decimal values to

$ set a= 12.4
$ set b=3.6
$ w=`expr $a - $b`
expr: non-numeric argument

or is there any other method to do this mathematics operation.
i need to use this into my script.
# 2  
Old 11-13-2009
This is quite a nice page on the subject

Floating Point Math in Bash | Linux Journal

---------- Post updated at 04:05 PM ---------- Previous update was at 03:44 PM ----------

When I tried these functions under ksh I had to remove the -q option for bc
# 3  
Old 11-13-2009
Here is how to do it in ksh. No need to use expr or subshells.
Code:
$ a=12.4
$ b=3.6
$ w=$((a-b))
$ echo $w
8.8

# 4  
Old 11-13-2009
That is true of ksh 93, in 88 the answer is 9 Smilie
# 5  
Old 11-17-2009
Data Not working

hi this is not working...
Its giving me an error.

w=$((a-b))
syntax error: `w=$' unexpected

can u suggest any other method
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

addition of two numbers

by the script, two files Q1 and Q2 will be generated on the system. Q1 will contain an integer number and Q2 also contain an integer number. i would like to add those numbers and put into new file. excerpt from my script 22 subcount=`echo $dir/Q$qid.txt` + `echo $dir/Q$qid.txt` 23 echo... (1 Reply)
Discussion started by: lookinginfo
1 Replies

2. Programming

Testing floating point numbers

Hi guys I have problem with my simple calculator, author of my book wrote One way I tried is to test if one the inpur number is grater than zero, and then substatct And my protptype function is #include <stdio.h> int main(void) { float a, b , result; ... (11 Replies)
Discussion started by: solaris_user
11 Replies

3. Shell Programming and Scripting

addition of both positive and negative numbers

Let, I have three numbers +00123.25 -00256.54 +00489.23 I need to sum up all those three numbers, after storing them in three variables (say var1, var2, var3). I used both expr and BC, but they didn't work for me. But, I am not able to sum up them, as I don't have any idea how to... (13 Replies)
Discussion started by: mady135
13 Replies

4. Shell Programming and Scripting

Help with addition of 2 numbers that are read from a file

I am trying to add free and used memory (so that i can compute percentage used)of remote nodes using shell script. I use the openssh-server,expect tool and ssh script. 1)login.txt (info of nodes): ip1|username|password ip2|username|password . . . 3)sshlogin.sh #!/bin/bash ... (1 Reply)
Discussion started by: marmik1903
1 Replies

5. Shell Programming and Scripting

How to get the ceiling value for floating numbers?

Dear guys; How can I get the ceiling value of any floating number using shell or awk scripts or functions. Example:- old values "7.2" or "7.8" or "7.5" --->>> ceiling function ---->>> new value "8". BR (6 Replies)
Discussion started by: ahmad.diab
6 Replies

6. Shell Programming and Scripting

floating point numbers in if

# if > then > echo "1" > else > echo "2" > fi -bash: How can i compare floating point numbers inside statement? (15 Replies)
Discussion started by: proactiveaditya
15 Replies

7. UNIX for Dummies Questions & Answers

Using Floating Numbers in String

Dear Unix Gurus, I have a list of files that I want to loop over....for example: sl40_z11.70.txt sl41_z11.40.txt sl42_z11.10.txt sl43_z10.80.txt using the script #!/bin/sh # echo -n "....enter first Z-coordinate position....."; read zpos q="scale=3; $zpos" p=0.3 #... (7 Replies)
Discussion started by: tintin72
7 Replies

8. Shell Programming and Scripting

Addition of all the numbers in a single file

Hi All , Want to know the "sum" of all the digits in below file called "/sample" .Could some one please let me know the script either command . cat /sample 12 34 23 23 Best Regards, Chinni . (5 Replies)
Discussion started by: chinni-script
5 Replies

9. Shell Programming and Scripting

floating point addition

hi, :) I have a file like this 10.456 123.567 456.876 234.987 ........ ....... What i want to do is ia have to add all those numbers and put the result in some other file. Any help pls. cheers RRK (8 Replies)
Discussion started by: ravi raj kumar
8 Replies

10. Shell Programming and Scripting

Addition of numbers in unix

Hi I have a file with specified format . Hxxxxxxxyyyyyggggggguuuuuuuuuurrrrrrrrrrrrrrrrrrrrrrrr xxxxxxxxyyyyyggggggguuuuuuuuuurrrrrrrrrrrrrrrrrrrrrrrr xxxxxxxxyyyyyggggggguuuuuuuuuurrrrrrrrrrrrrrrrrrrrrrrr xxxxxxxxyyyyyggggggguuuuuuuuuurrrrrrrrrrrrrrrrrrrrrrrr... (3 Replies)
Discussion started by: asinha63
3 Replies
Login or Register to Ask a Question