float input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting float input
# 1  
Old 03-04-2009
float input

how to input float data type in bash shell programming in linux?
I am new to it so unaware to use the commands plz help me out.
thank you.
# 2  
Old 03-04-2009
Looks..H..Work..

mmm..

Thanks
Sha
# 3  
Old 03-04-2009
Quote:
Originally Posted by Shahul
Looks..H..Work..

mmm..

Thanks
Sha
Huh Smilie what kind of answer is this?

There are a lot of threads regarding floating arithmetic with shell scripting, search for floating arithmetic.

Regards
# 4  
Old 03-05-2009
float input

My problem is to input float value.
I have done it in this way
#!bin/bash
sum=0.0
read a
sum=`expr $a + $sum | bc`
echo sum
but when i entered float no. then it is giving expr...non numeric argument .
ok
thanx any ways
# 5  
Old 03-06-2009
MySQL

Hi,

Small correction...

hope this should work...
#!bin/bash
sum=0.0
read a
sum=`echo $a + $sum | bc`
echo $sum

Thanks
Sha
# 6  
Old 03-06-2009
thanks

Thanx alot .
That is working.
But sorry I want to ask more
how can we implement end of file command in shell
means I have to insert nos. from user till he presses "ctrl c" and after that display their addition .
How can I do this.
Thanking in anticipation.
Have a good day.

Last edited by purva; 03-06-2009 at 05:59 AM..
# 7  
Old 03-06-2009
Hi ,

For division,, you can use like this...(using awk)
Code:
 echo "test"|awk -v var1=3.3 -v var2=3 '{print var1 / var2}'

Thanks
Sha
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Float array sum

Hi everyone, I'm having some trouble with float array. When i try to get the array sum with float numbers i get this error line 39: soma + 2.34 | bc: syntax error: invalid arithmetic operator (error token is ".34 | bc") 26 Somar() { 27 echo "Quantos numeros deseja somar?" 28 read... (4 Replies)
Discussion started by: berveglieri
4 Replies

2. Red Hat

What is float IP?

:confused:We have two servers one active and one stand by as follows Active 202.61.9.9 Stand by 202.61.9.10 Float IP 202.61.9.8 What is use of this float IP? How it is configured? (1 Reply)
Discussion started by: manalisharmabe
1 Replies

3. Shell Programming and Scripting

Is there a simpler way to validate user input for float?

I'm trying to only read price (FLOAT (i.e 1.10, 3.14, etc etc)) If the input is just an integer, I will add a .00 behind. (i.e 3 becomes 3.00 , 20 becomes 20.00) If the input is without 2 decimal places, I'll add a 0. (i.e 3.1 becomes 3.10) I tried using the below code, it works but I don't... (6 Replies)
Discussion started by: andylbh
6 Replies

4. Shell Programming and Scripting

float to normal

I have a file with 2 columns . One of the line looks like the following. Is it possible to convert every float no in column 2 to integer. input NM_032881 6.03787973608527e-05 output 0.0000603787..... (2 Replies)
Discussion started by: quincyjones
2 Replies

5. Programming

Float issues

i am adding two floating point numbers and i want to store in a character pointer... float f1 ; float f2 ; char *c = NULL; printf("Enter 2 floating numbers\n"); scanf("%f %f",&f1,&f2); f1 = f1+f2; sprintf(c, "%f", f1 ); when i execute this, i am... (3 Replies)
Discussion started by: pgmfourms
3 Replies

6. UNIX for Dummies Questions & Answers

input a float data and add them in shell in linux

I want to input a float data and add them in shell in linux. I am new user of it can anyone tell me how I can do it? thanx (5 Replies)
Discussion started by: purva
5 Replies

7. Programming

math.h: float ceilf(float x)

Good morning, I'm testing the use of ceilf: /*Filename: str.c*/ #include <stdio.h> #include <math.h> int main (void) { float ceilf(float x); int dev=3, result=0; float tmp = 3.444f; printf("Result: %f\n",ceilf(tmp)); return 0; } (1 Reply)
Discussion started by: jonas.gabriel
1 Replies

8. UNIX for Dummies Questions & Answers

Float calculations

As expr is used for integer calculations, which command is used for float calculations. (1 Reply)
Discussion started by: sharmavr
1 Replies

9. Shell Programming and Scripting

float comparison

I had a variable 1:80 8 in one varialbe say var=1:80 8 i comapred the below if then -- else ---- thought if condition is true its always going in the else condition....its not giving any compilation errror also....is there any problem bcoz of space... can some one help... (3 Replies)
Discussion started by: mkan
3 Replies

10. Shell Programming and Scripting

expr+float argument: how can i do?

Hi everybody, I want to know how can i use the command 'expr' to manipulate float number , i have a shell bash and when (for example) i do: y1=`expr \( 1/ 16 \)` it returns 0 and if i do y1=`expr \( 1.6 / 16 \)` it returns non numeric argument. is there another command for mathematic... (4 Replies)
Discussion started by: mips
4 Replies
Login or Register to Ask a Question