IF statement on floating point variable in scientific format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting IF statement on floating point variable in scientific format
# 1  
Old 12-08-2011
IF statement on floating point variable in scientific format

Hi all,
I'm struggling Smilie to make a an if statement on two variables in scientific format.
e.g.
Code:
a=1.23e+01
b=3.21e+02

I know that it can be done with bc if the variable are not in scientific format.
But what to do in this case???
Thank you,
# 2  
Old 12-08-2011
awk can understand numbers in scientific format.

So, what what are you actually trying to do? Compare them how?
# 3  
Old 12-08-2011
Quote:
Originally Posted by Corona688
awk can understand numbers in scientific format.

So, what what are you actually trying to do? Compare them how?
I just would like to do something if one is greater than the other; something like

Code:
if(${a}>${b})
 echo 1
else
 echo 2

# 4  
Old 12-08-2011
Code:
if awk -v A="1.23e+01" -v B="3.21e+02" 'BEGIN { if(A>B) exit 0;  exit 1 }'
then
        echo "A>B"
else
        echo "A<=B"
fi

This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add leading zeros in floating point variable

I need to add leading zeros in a floating point numbers. The length of the number should be 13 including decimal. The input number is changing so number of leading zeros is not fix. For example input output 216.000 000000216.000 1345.000 000001345.000 22345.500 ... (4 Replies)
Discussion started by: reeta_shri
4 Replies

2. Programming

Floating Point

Anyone help me i cant found the error of floating point if needed, i added the code complete #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> typedef struct { int hh; int mm; int ss; char nom; int punt; }cancion; typedef struct... (9 Replies)
Discussion started by: Slasho
9 Replies

3. Shell Programming and Scripting

Floating point to integer in variable length lines

Hi ! I'm looking for a way to transform certain floating point numbers in a one-line, variable length file to integers. I can do this in a crude way with sed : sed -e 's/0\.\(\):/\1:/g' -e 's/0\.0\(\):/\1:/g' -e 's/1\.000:/100:/g' myfile ... but this doesn't handle the rounding correctly. ... (3 Replies)
Discussion started by: jossojjos
3 Replies

4. Shell Programming and Scripting

how to compare 2 floating point no.

Hi, Could any one tell me how to compare to floating point no. using test command. As -eq option works on only intergers. i=5.4 if then echo "equal" else echo "not equal" fi here output will be equal even though no. are unequal. Thanks, ravi (1 Reply)
Discussion started by: useless79
1 Replies

5. Linux

Floating Point Exception

Hi, I am compiling "HelloWorld" C progam on 32-bit CentOS and i want to execute it on 64-bit CentOS architecture. For that i copied the a.out file from 32-bit to 64-bit machine, but while executing a.out file on 64bit machine I am getting "Floating point exception error". But we can run... (3 Replies)
Discussion started by: Mandar123
3 Replies

6. Linux

Floating point exception !!!

Hi, I have linux fedora 4 ver., 2.6 kernal. And qmail & mysql & samba servers are already configured on this server. When I try to install any package like squidguard ,dansguardian,webmin,rsnapshots with command rpm -ivh . It is giving error as “Floating point exception" Snap View is... (3 Replies)
Discussion started by: ssk01
3 Replies

7. Programming

Floating point error in C

Hi, see the simple code below double i; i=8080.9940; printf(" val :%.30f\n",i); output i m getting is val :8080.993999999999700000000000000 when i m expecting val :8080.9940 what happens?how can i avoid it? thanks... (2 Replies)
Discussion started by: Hara
2 Replies

8. Shell Programming and Scripting

Rounding off the value of Floating point value

Hello, i have some variables say: x=1.4 y=3.7 I wish to round off these values to : x = 2 (after rounding off) y = 4 (after rounding off) I am stuck. Please help. (7 Replies)
Discussion started by: damansingh
7 Replies

9. Shell Programming and Scripting

floating point shell variable

I have a two files >cat file1 jjjjj 10.345 6.673 ppp 9.000 5.883 >cat file2 mmm 80 10 jjjjj 10.305 6.873 ppp 9.000 5.883 I am reading file 1 line by line , and look for the string jjjj and then read the line in file 2 with jjjj I want to get the... (5 Replies)
Discussion started by: jojan
5 Replies

10. Shell Programming and Scripting

floating point variable in UNIX script

HI all, Can someone help me how to use or assign a floating point value in a variable in a unix script. I dont know how to use it. for example, I am to assign a variable VAR1 a value of 2.34 and evaluate if a certain vaue is greater or less than to it. That is, if var1 > 2.13 will do... (7 Replies)
Discussion started by: darry
7 Replies
Login or Register to Ask a Question