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
VB doesn't have a built-in function for rounding n...
Author:
Arkady Adler
E-mail:
Click to e-mail author
Submitted:
8/25/2000
Version:
VB3
Compatibility:
VB3, VB4, VB5, VB6
Category:
Mathematics
Views:
10202
VB doesn't have a built-in function for rounding numbers (unlike most other languages), so I wrote one myself. Enjoy!
Declarations:
'none
Code:
Function fnRound(dblNumber As Double, Optional bytSignificantDigits As Byte) As Double Dim strTemp As String, bytPosition As Byte strTemp = dblNumber bytPosition = InStr(strTemp, ".") If bytPosition > 0 Then If Val(Mid(strTemp, bytPosition + bytSignificantDigits + 1, 1)) > 4 Then fnRound = CDbl(Left(strTemp, bytPosition + bytSignificantDigits)) _ + CDbl("0." & Format(1, String(bytSignificantDigits, "0"))) Else fnRound = Left(strTemp, bytPosition + bytSignificantDigits) End If Else fnRound = strTemp End If End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement