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
Rounding off the value of Floating point value damansingh Shell Programming and Scripting 7 05-21-2008 09:46 AM
Number count per number ranges shirleyeow Shell Programming and Scripting 5 12-19-2007 04:06 AM
to print number one less than actual number cdfd123 Shell Programming and Scripting 4 09-06-2007 06:56 AM
Rounding problem shash UNIX for Dummies Questions & Answers 2 01-18-2007 05:33 AM
Rounding off using BC. noodlesoup Shell Programming and Scripting 3 09-11-2006 12:38 AM

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 07-17-2008
damansingh damansingh is offline
Registered User
  
 

Join Date: May 2008
Posts: 11
Rounding off to the next whole number

Hello,
I searched a lot on this Forum.
Please help me with the below problem.

I want to divide two numbers and the result should be the next nearest whole number.

E.G. Dividing 10.8/5 ideally gives 2.16. But the result should be 3 i.e. rounded off to the next whole number.

Any help will be deeply appreciated.
  #2 (permalink)  
Old 07-17-2008
mirusnet's Avatar
mirusnet mirusnet is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 146
round a number
  #3 (permalink)  
Old 07-17-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,912
Humm, if you really want to round 10.8/5 to an integer the answer should be 2 not 3. What you are looking for is to round up i.e. ceil(10.8/5)

Code:
$ num=2.16
$ print $((floor(num)))
2
$ print $((ceil(num)))
3
$
Sponsored Links
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 07:47 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