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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to compare big real numbers padarthy Shell Programming and Scripting 4 10-02-2007 02:23 AM
How to Compare Floating point / real numbers padarthy Shell Programming and Scripting 13 09-24-2007 05:03 PM
Compare integer value with decimal MARY76 Shell Programming and Scripting 3 07-25-2007 06:47 AM
Devision of Decimal Numbers? Vozx Shell Programming and Scripting 4 12-07-2005 03:26 AM
add numbers with decimal place in UNIX tads98 Shell Programming and Scripting 4 07-21-2005 02:17 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-02-2005
tmxps's Avatar
Registered User
 

Join Date: Sep 2005
Posts: 8
compare decimal numbers

Hi anyone,

i need to compare two decimal numbers

i thought that it could be do it with if but...

So, i'm writing in csh and i really apreciate if anyone can help me

if ( $ppl_kn <= $ppl_wb ) then
echo "############# KNdiscount model has the lowest perplexity"
set ppl_LM_choosed = $ppl_LM_kn
set LM_choosed = $LM_kn
else
echo "############# WBdiscount model has the lowest perplexity"
set ppl_LM_choosed = $ppl_LM_wb
set LM_choosed = $LM_wb
endif

Many thanks
Reply With Quote
Forum Sponsor
  #2  
Old 11-02-2005
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
That should be fine....
Code:
#!/usr/bin/csh -f

set ppl_kn = 7
set ppl_wb = 6

if ( $ppl_kn <= $ppl_wb ) then
  echo "KNdiscount model has lowest perplexity"
else
  echo "WBdiscount model has lowest perplexity"
endif
Works for me...

Also; people are going to yell "Don't use csh for scripting", for good reason too...

Cheers
ZB
Reply With Quote
  #3  
Old 11-02-2005
tmxps's Avatar
Registered User
 

Join Date: Sep 2005
Posts: 8
Thanks by your quick reply.

however does not work if i make
set ppl_kn = 7.1
set ppl_wb = 6.8
or
set ppl_kn = 7,1
set ppl_wb = 6,8

The numbers i need to compare are not integers.

Thanks anyway.
Reply With Quote
  #4  
Old 11-02-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
ksh88 only has integers. Here is how I solve this problem in ksh88. You get translate the technique to csh. Or you could switch to a real shell.
Reply With Quote
  #5  
Old 11-02-2005
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Use perl...
Code:
#!/usr/bin/perl

my $ppl_kn = 1.4;
my $ppl_wb = 1.2;

if ( $ppl_kn <= $ppl_wb ) {
   printf "KNdiscount model has lowest perplexity\n";
} else {
   printf "WBdiscount model has lowest perplexity\n";
}
Cheers
ZB
Reply With Quote
  #6  
Old 11-02-2005
Registered User
 

Join Date: Jul 2005
Posts: 137
Code:
ruby -e 'puts ($*.first.to_f <= $*.last.to_f) ? 1 : 0' 3.14 9
Output:

1
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0