Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I round a number up?

Status
Not open for further replies.

emblewembl

Programmer
May 16, 2002
171
GB
I need to be able to round a number up e.g. 2.3 up to the next whole number.

SO:

2.3 should become 3
4.1 should become 5 etc.

How can I do this? i love chocolate
 
try this...


Dim i As Integer
dim real as double

'initialize real with a decimal number, say 5.1
real = 5.1
'You can get this from a for or any where...


i = real
If i < real Then
i = i + 1
End If

'Display i, i has your rounded up number now.


--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Try

lngRounded = -(Int(-yourNumber))

&quot;Returns the integer portion of a number.

Int(number)
Fix(number)
The number argument can be any valid numeric expression. If number contains Null, Null is returned.

Remarks
Both Int and Fix remove the fractional part of number and return the resulting integer value.

The difference between Int and Fix is that if number is negative, Int returns the first negative integer less than or equal to number, whereas Fix returns the first negative integer greater than or equal to number. For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.


Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Thanks both of you for your answers, but I'm not sure either really do what I want. After much searching I have finally found the asp.net way of doing this so I'll post it here in case anyone else should be searching in the future! To round a decimal number up to the next biggest integer, use:

Dim numLines As Decimal = 3.1
Dim result As Integer

result = System.Math.Ceiling(numLines)

This will return '4'.
i love chocolate
 
Hmmm...fair pount, John.....

Put it down to a bug.....!

Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top