Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Module VBModule
Sub Main()
Console.WriteLine("Hello, world!")
Console.WriteLine(Roundup(1448.374,2))
End Sub
'CreatedBy: Dhaneshwar
'CreatedAt: 20-Feb-18
'LastModBy: Dhaneshwar
'LastModAt: 21-Jan-19
'Desc: RoundUp function - developed using online editor. Uncomment Console lines for debugging.
'LastComment:Fixed a problem in the procedure
Public Function Roundup(ByVal number As Double, ByVal Num_Digits As Integer) As Double
Dim isNegative As Boolean = false
IF number < 0
isNegative = true
number = -1 * number
END IF
Dim numberStr As String = number.ToString()
Console.WriteLine(numberStr)
Dim decPointIndex as Integer = numberStr.IndexOf(".")
Console.WriteLine(decPointIndex)
IF decPointIndex >= 0
Dim whole As Integer = Math.Truncate(number)
Console.WriteLine(whole)
Dim decimalPartStr As String = numberStr.Substring(decPointIndex + 1)
Console.WriteLine(decimalPartStr)
IF decimalPartStr.Length > Num_Digits
Dim decimalPartForGivenNum_Digits As String = decimalPartStr.Substring(0, Num_Digits)
Console.WriteLine(decimalPartForGivenNum_Digits)
Dim decimalPartAfterGivenNum_Digits As String = decimalPartStr.Substring(Num_Digits)
Console.WriteLine(decimalPartAfterGivenNum_Digits)
Dim decimalPartAfterGivenNum_DigitsInt As Long = CLng(decimalPartAfterGivenNum_Digits)
Console.WriteLine(decimalPartAfterGivenNum_DigitsInt)
Dim addValueForRoundUp As Double = 0.00
IF decimalPartAfterGivenNum_DigitsInt > 4
addValueForRoundUp = 0.1 ^ Num_Digits
Console.WriteLine(addValueForRoundUp)
END IF
Dim ForDecimalPoint As Double = 0.1 ^ Num_Digits
Dim numberAfterRoundUp As Double = whole + (CLng(decimalPartForGivenNum_Digits) * ForDecimalPoint) + addValueForRoundUp
Console.WriteLine(numberAfterRoundUp)
number = numberAfterRoundUp
END IF
END IF
IF isNegative
number = -1 * number
END IF
Return number
End Function
End Module
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more