The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl: Search for string on line then compare numbers! Crypto Shell Programming and Scripting 2 01-22-2008 01:50 AM
Get real value from real-time systems iBot Complex Event Processing RSS News 0 01-14-2008 02:10 AM
Compare two arrays in sh or compare two fields rijeshpp Shell Programming and Scripting 0 10-31-2007 02:47 AM
How to Compare Floating point / real numbers padarthy Shell Programming and Scripting 13 09-24-2007 09:03 PM
compare decimal numbers tmxps Shell Programming and Scripting 5 11-02-2005 06:46 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-02-2007
padarthy padarthy is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 15
how to compare big real numbers

Hi everyone,

I need to compare 2 big Floating/Real numbers in a script.

After the comparission it is showing worng values in my script.

echo "Enter value1"
read value1
echo "Enter value2"
read value2

Result=`echo "if($value1 > $value2) 1" | bc`

if [ $Result -eq 1 ]; then
echo "$value1 is greater"
fi

Please correct this code ..
  #2 (permalink)  
Old 10-02-2007
padarthy padarthy is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 15
how to compare big real numbers

Hi everyone,

I need to compare 2 big Floating/Real numbers in a script.

After the comparission it is showing worng values in my script.

echo "Enter value1"
read value1
echo "Enter value2"
read value2

Result=`echo "if($value1 > $value2) 1" | bc`

if [ $Result -eq 1 ]; then
echo "$value1 is greater"
fi

Please correct this code ..
  #3 (permalink)  
Old 10-02-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
The script seems correct, but you may substitute "bc" with "bc -l".
  #4 (permalink)  
Old 10-02-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
try echo $Result to see what it actually contains.
  #5 (permalink)  
Old 10-02-2007
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,945
What shell are you using? Not all shells support floating
point number comparison.

If you are using ksh you may need to do something like

echo "Enter value1"
typeset -F value1
read value1
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:20 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0