Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Round Up and Round Down in VB
Author:
Syed Irtaza Ali
E-mail:
Click to e-mail author
Website:
http://www.edreamz.net
Submitted:
7/23/2004
Version:
VB3
Compatibility:
VB3, VB4, VB5, VB6
Category:
Mathematics
Views:
109701
Two simple functions that are not found in VB. Suppose you have a number '3.376'. Now when you will use the RoundUp function you will get the result as '4.0'. By using RoundDown function the result would be '3.0'. However, for .NET you could use the Math.Floor and Math.Ceiling methods.
Declarations:
'none
Code:
Public Function roundDown(dblValue As Double) As Double On Error GoTo PROC_ERR Dim myDec As Long myDec = InStr(1, CStr(dblValue), ".", vbTextCompare) If myDec > 0 Then roundDown = CDbl(Left(CStr(dblValue), myDec)) Else roundDown = dblValue End If PROC_EXIT: Exit Function PROC_ERR: MsgBox Err.Description, vbInformation, "Round Down" End Function Public Function roundUp(dblValue As Double) As Double On Error GoTo PROC_ERR Dim myDec As Long myDec = InStr(1, CStr(dblValue), ".", vbTextCompare) If myDec > 0 Then roundUp = CDbl(Left(CStr(dblValue), myDec)) + 1 Else roundUp = dblValue End If PROC_EXIT: Exit Function PROC_ERR: MsgBox Err.Description, vbInformation, "Round Up" End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2023 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement