The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Comparing Decimal Numbers Grizzly Shell Programming and Scripting 3 10-05-2009 03:17 AM
Insert a decimal point lyoncc Shell Programming and Scripting 4 06-04-2007 05:40 PM
how to get rid of decimal point? cin2000 Shell Programming and Scripting 2 12-27-2005 12:26 PM
How To Make Decimal Point Fall On The 15th Character On The Screen Vozx Shell Programming and Scripting 3 12-08-2005 04:17 PM
comparing two decimal values in KSH nandinisagar Shell Programming and Scripting 4 11-15-2005 06:36 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 2 Weeks Ago
kinny kinny is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 32
Comparing two numbers with decimal point

How to compare two numbers with decimal points ?

Is there a way in bash to do this?
  #2 (permalink)  
Old 2 Weeks Ago
frans's Avatar
frans frans is offline
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 86
I would say bc (type man bc)
  #3 (permalink)  
Old 2 Weeks Ago
Scrutinizer Scrutinizer is online now
Registered User
  
 

Join Date: Nov 2008
Posts: 597
Or use ksh93 instead of bash
  #4 (permalink)  
Old 2 Weeks Ago
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,511
Quote:
Originally Posted by kinny View Post
How to compare two numbers with decimal points ?

Is there a way in bash to do this?
you have awk at your disposal.
Code:
$ awk 'BEGIN{if(12.14>12.13){ print "greater"}}'
greater
  #5 (permalink)  
Old 2 Weeks Ago
Scrutinizer Scrutinizer is online now
Registered User
  
 

Join Date: Nov 2008
Posts: 597
ksh93:
Code:
if (( 12.14>12.13 )); then echo greater; fi
bash:
Code:
if (( $(bc <<< "12.14>12.13") > 0 )); then echo greater; fi
posix:
Code:
if [ $(echo "12.14>12.13"|bc) -gt 0 ] ; then echo greater; fi
  #6 (permalink)  
Old 2 Weeks Ago
ahmad.diab's Avatar
ahmad.diab ahmad.diab is offline
Registered User
  
 

Join Date: May 2008
Location: Amman Jordan in MEA
Posts: 228
Quote:
Originally Posted by Scrutinizer View Post
ksh93:
Code:
if (( 12.14>12.13 )); then echo greater; fi
bash:
Code:
if (( $(bc <<< "12.14>12.13") > 0 )); then echo greater; fi
posix:
Code:
if [ $(echo "12.14>12.13"|bc) -gt 0 ] ; then echo greater; fi
Code:
bash and posix expression didn't work for me!!!!..I have the below OS.

SunOS server2 5.10 Generic_118833-36 sun4u sparc SUNW,Netra-210
  #7 (permalink)  
Old 2 Weeks Ago
Scrutinizer Scrutinizer is online now
Registered User
  
 

Join Date: Nov 2008
Posts: 597
Quote:
Originally Posted by ahmad.diab View Post
Code:
bash and posix expression didn't work for me!!!!..I have the below OS.

SunOS server2 5.10 Generic_118833-36 sun4u sparc SUNW,Netra-210
Bash I am not surprised since I gather that is not a happy marriage with Solaris (is it even installed on your system?). However the problem with posix compliant version puzzles me. What is the output of this command on your system:
Code:
echo "12.13>12.14"|bc; echo "12.14>12.13"|bc
Closed Thread

Bookmarks

Tags
comparsion

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 01: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