Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 17th, 2003, 06:35 AM
Knappe Knappe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 38 Knappe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
How to round up a decimal value to next integer?

Hello!
Is there a format function that rounds a decimal value to the next integer value? I'm not talking about the nearest integer. I need the value to be rounded up to the next integer.

Reply With Quote
  #2  
Old November 17th, 2003, 07:08 AM
Knappe Knappe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 38 Knappe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
I found a function named fix.

I'm using it like this: fix(value1 / value2) +1.

I think that this is working as I want it to. Can someone confirm if this is right?

I also found a CInt function but I don't really know what it does...

Reply With Quote
  #3  
Old November 17th, 2003, 08:19 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,176 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 42 m 4 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
the cInt function returns the integer value of a value - but depending on the data type, it may or may not round that value (in the case of Currency, it will). the Round() function will round a value, and nested inside the cInt, it will return the next highest integer value. You can do this

Code:
dim intI as integer
intI = cint(Round(value))
__________________
Fisherman

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein

Reply With Quote
  #4  
Old November 17th, 2003, 09:50 AM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,852 Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 36 m 5 sec
Reputation Power: 766
I haven't tried this code but it might work, depends if the integer divide rounds the decimal number or not.

newInt = (oldDec \ 1) + 1

Reply With Quote
  #5  
Old November 17th, 2003, 11:03 AM
Knappe Knappe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 38 Knappe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Thanks guys!
I'm gonna use the fix function. I think it works best in this case. It looks like this:

fix(decValue) + 1

Reply With Quote
  #6  
Old November 20th, 2003, 02:33 AM
sir_drinxalot's Avatar
sir_drinxalot sir_drinxalot is offline
Known to taste like chicken
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: In front of my computer
Posts: 228 sir_drinxalot User rank is Sergeant (500 - 2000 Reputation Level)sir_drinxalot User rank is Sergeant (500 - 2000 Reputation Level)sir_drinxalot User rank is Sergeant (500 - 2000 Reputation Level)sir_drinxalot User rank is Sergeant (500 - 2000 Reputation Level)sir_drinxalot User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 13 h 59 m 40 sec
Reputation Power: 19
Send a message via MSN to sir_drinxalot
Facebook
what about a trunc function to get rid of the decimal (not too sure of syntax for it in vb) and then add 1

Reply With Quote
  #7  
Old November 20th, 2003, 07:49 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,176 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 42 m 4 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
That would work. There is a formatnumber function where you can designate how you want the number displayed, but it would be easier to do it one of the other ways.

Reply With Quote
  #8  
Old November 27th, 2003, 12:03 PM
harry sachz's Avatar
harry sachz harry sachz is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: So. Cal
Posts: 1 harry sachz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to harry sachz
just an idea

my first post so bear with me....

with the previous ideas, the + 1 wouldn't work if the value didn't have a decimal... however, the int function rounds correctly as long as it's a negative number...

so.. i tried:

dim intNumber as integer

(Int (intNumber / -4) * -1)

... it works for my purposes.. take from it what you will

:-)

Reply With Quote
  #9  
Old November 27th, 2003, 02:01 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,176 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 42 m 4 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
for that matter, you could do somethingalong these lines

Code:
if intNumber < 0 then
       intFinalValue = cint(abs(intSomeInteger))
       intFinalValue = intFinalValue * -1
else
       intFinalValue = cint(intSomeInteger)
Endif

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > How to round up a decimal value to next integer?


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway