|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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... |
|
#3
|
||||
|
||||
|
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 |
|
#4
|
|||
|
|||
|
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 |
|
#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 |
|
#6
|
||||
|
||||
|
what about a trunc function to get rid of the decimal (not too sure of syntax for it in vb) and then add 1
|
|
#7
|
||||
|
||||
|
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.
|
|
#8
|
||||
|
||||
|
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 :-) |
|
#9
|
||||
|
||||
|
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
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > How to round up a decimal value to next integer? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|