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
Floating point exception !!! ssk01 Linux 3 12-24-2008 02:20 PM
Floating point error in C Hara High Level Programming 2 06-18-2008 05:43 AM
floating point problem vijlak High Level Programming 4 03-08-2007 04:18 AM
floating point addition ravi raj kumar Shell Programming and Scripting 8 12-22-2006 02:47 AM
Floating Point Division gsatch Shell Programming and Scripting 1 07-25-2002 04:03 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 05-21-2008
damansingh damansingh is offline
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.
  #2 (permalink)  
Old 05-21-2008
aju_kup aju_kup is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 189
Code:
$ typeset -i var
$ var=100.100
$ echo $var
100
  #3 (permalink)  
Old 05-21-2008
damansingh damansingh is offline
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
  #4 (permalink)  
Old 05-21-2008
aju_kup aju_kup is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 189
can u pls show me ur script. even I am using ksh
  #5 (permalink)  
Old 05-21-2008
damansingh damansingh is offline
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.
  #6 (permalink)  
Old 05-21-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Try this:

Code:
 numberOfFilesGenerated=`echo $totalRowCount $rowCountEntered | awk '{printf("%d", $1/$2+0.9}'`
Regards
  #7 (permalink)  
Old 05-21-2008
aju_kup aju_kup is offline
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
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 11:03 PM.


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