by Thomas Bishop (1 Submission)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 25th August 2000
Date Added: Mon 8th February 2021
Rating:
(1 Votes)
Round up currency amounts to next quarter.
API Declarations
Dim srTotal As String
Dim Quarters As Integer
' This routine assumes that you have created a form
' containg a text box for entering the amount to be rounded called "txtCost",
' a command button called "cmdRound" to do the calculation,
' and a label to display the result called "lblRounded".
' Any amount half a penny above the 25 cent mark will be rounded up
' to the next quarter dollar amount.
TotCost = Val(txtCost.Text) 'insert entered value into var
srTotal = CCur(TotCost) 'round value to two decimals and convert to string
srTotal = Format(srTotal, "currency") 'force string to give 2 decimal places
'round up to next highest quarter dollar
If Val(Right$(srTotal, 2)) > 75 Then
srTotal = Int(srTotal) + 1
ElseIf Val(Right$(srTotal, 2)) > 50 Then
Quarters = 3
srTotal = Int(srTotal) + (0.25 * Quarters)
ElseIf Val(Right$(srTotal, 2)) > 25 Then
Quarters = 2
srTotal = Int(srTotal) + (0.25 * Quarters)
ElseIf Val(Right(srTotal, 2)) > 0 Then
Quarters = 1
srTotal = Int(srTotal) + (0.25 * Quarters)
End If
srTotal = Format(srTotal, "currency") 'convert string to currency again
lblRounded.Caption = srTotal 'display rounded value in label
End Sub