How to perform floating division in shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to perform floating division in shell script?
# 1  
Old 01-04-2012
How to perform floating division in shell script?

I want to perform the below division operation in shell script and round the value.

Code:
val1=6000
val2=5000
res=val1/val2 ----> 1.2---> Round to 2

Please help.
# 2  
Old 01-04-2012
Bad answer. Omit this post.

EDIT:
Did you thank it? Then I will re-write my original post, but it wasn't what you are looking for, it outputs a decimal number, without ceiling.
Code:
$ echo "scale=1; $val1 / $val2" | bc
1.2

Regards,
Birei

Last edited by birei; 01-04-2012 at 10:28 AM..
This User Gave Thanks to birei For This Post:
# 3  
Old 01-04-2012
Thank you. How to round of the output to 2 here??
# 4  
Old 01-04-2012
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to perform appending of .sql files

Hi, We are having multiple .sql files generated programatically which is not containing.. create or replace -- at the start and / -- at the end We need to append those .sql files with the above 2 statements at their respective positions. We will be really thankful to get responses... (6 Replies)
Discussion started by: Rami Reddy
6 Replies

2. Shell Programming and Scripting

UNIX shell script - cut specified line and perform loop

Guys, I have a requirement as below. consider,if i use df command, its getting the below output. file system kbytes used avail %used Mounted on /dev/sample/ 45765 40000 5765 50% / /dev/filesys/ 30000 20000 1000 80% /u .... .... Now i wanted to cut the /u... (11 Replies)
Discussion started by: AraR87
11 Replies

3. Homework & Coursework Questions

Shell Script to read a tab delimited file and perform simple tasks

1. The problem statement, all variables and given/known data: Hello! I need help with this problem bash shell scripting that basically just reads the data in a tab delimited file and does the following below 1. Read in the data file Survey.txt and assign the column values to variables of... (6 Replies)
Discussion started by: jsmith6932
6 Replies

4. Shell Programming and Scripting

Unix Script -- Unable to perform division

I'm new to scripts, i wrote the below script to capture the percentage of FreeMemory available in Linux box. Output of UsedfreeMemory is displayed as '0'. I'm expecting the output like 0.89 (or) .89 --- ( 0.89 perferable) Anyone can help me on this pls. ... (3 Replies)
Discussion started by: murali1687
3 Replies

5. UNIX for Dummies Questions & Answers

How to perform string replace in shell script?

I have value like ABCDEF,BBCCDD in a shell variable, now i would like to have ABQWEF,BBQWDD in the same shell variable. How can i replace the char at position 3&4 with QW in shell script? (3 Replies)
Discussion started by: vel4ever
3 Replies

6. Shell Programming and Scripting

shell script - search a file and perform some action

hi, i have a service on unix platform, it will generate traces in a particular folder i want to check using shell script if traces exist, then perform some action else continue to be in loop. filename is service.tra can you please help? thanks (4 Replies)
Discussion started by: gauravah
4 Replies

7. Shell Programming and Scripting

How to compare floating point numbers in shell script?

How can we compare 2 floating point numbers in SHELL script? (11 Replies)
Discussion started by: dearanik
11 Replies

8. Shell Programming and Scripting

Floating Division in Linux

Hi everyone , have a great day given below is the excerpt of code k=`grep -i success /var/seamless/spool/tdr/ERS_$date1$time1* | wc -l`; l=`grep -i fail /var/seamless/spool/tdr/ERS_$date1$time1* | wc -l`; m=`grep -i entertain /var/seamless/spool/tdr/ERS_$date1$time1* | wc -l`; n=$(($k+$l))... (3 Replies)
Discussion started by: Dastard
3 Replies

9. Shell Programming and Scripting

division operation in shell script

Hi guys I am trying to divide 2 variables that I got during the execution of script, but I unable to divide the variables. pls help. Hers is the code. num_tasks=`sqlplus -s batch_user/batch_user@acsblest << EOF1 set heading off SET FEEDBACK OFF SET PAGESIZE 0 SET LINESIZE 900 select... (31 Replies)
Discussion started by: ragha81
31 Replies

10. Shell Programming and Scripting

Floating Point Division

Does anyone have a simple way of doing floating point ("fp") division? For example, if I divide 3 by 5, I can get 0.6. The built-in calc (`bc`) will perform fp multiplication, but not division, at least not straight-up (i.e., starting bc and just typing in 3/5). I am trying to do this using... (1 Reply)
Discussion started by: gsatch
1 Replies
Login or Register to Ask a Question