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
Floating point error in C Hara High Level Programming 2 06-18-2008 02:43 AM
Floating point exception !!! ssk01 Linux 2 05-14-2008 02:58 AM
floating point problem vijlak High Level Programming 4 03-08-2007 01:18 AM
floating point addition ravi raj kumar Shell Programming and Scripting 8 12-21-2006 11:47 PM
Floating Point Division gsatch Shell Programming and Scripting 1 07-25-2002 01:03 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-21-2008
Registered User
 

Join Date: May 2008
Posts: 11
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.
Reply With Quote
Forum Sponsor
  #2  
Old 05-21-2008
Registered User
 

Join Date: Jul 2006
Posts: 189
Code:
$ typeset -i var
$ var=100.100
$ echo $var
100
Reply With Quote
  #3  
Old 05-21-2008
Registered User
 

Join Date: May 2008
Posts: 11
Hi aju_kup,
Thanks for replying.

typeset -i var
var=100.500
echo $var


When i try your suggestion, it gives me an error which is:
check4.sh: line 2: 100.500: syntax error in expression (error token is ".500")

here check4.sh is the file which contained your suggested code.

I am working on KShell.

Please see to it.
Thanks
Reply With Quote
  #4  
Old 05-21-2008
Registered User
 

Join Date: Jul 2006
Posts: 189
can u pls show me ur script. even I am using ksh
Reply With Quote
  #5  
Old 05-21-2008
Registered User
 

Join Date: May 2008
Posts: 11
Sure friend,

rowCountEntered=98
totalRowCount=1000

numberOfFilesGenerated=`echo $totalRowCount $rowCountEntered | awk '{print $1/$2}'`

echo $numberOfFilesGenerated
10.20

Instead of 10.20, i want the variable numberOfFilesGenerated should return 11.

In Anticipation.
Reply With Quote
  #6  
Old 05-21-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,317
Try this:

Code:
 numberOfFilesGenerated=`echo $totalRowCount $rowCountEntered | awk '{printf("%d", $1/$2+0.9}'`
Regards
Reply With Quote
  #7  
Old 05-21-2008
Registered User
 

Join Date: Jul 2006
Posts: 189
rowCountEntered=98
totalRowCount=1000

typeset -i numberOfFilesGenerated
numberOfFilesGenerated=`echo $totalRowCount $rowCountEntered | awk '{print $1/$2}'`


echo $numberOfFilesGenerated
10
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 11:00 PM.


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