I need to round a number as follows:
if the value behind the decimals is <.25 then it should round down to the whole number, if the value is >.25 but <.5 it should round up to .5, if the value is <.5 it should round up to the next whole number.
an example:
1.24 becomes 1
1.45 becomes 1.5
1.75 becomes 2
I've found this solution below, but need to add the rounding up part to the next whole number:
Function CustomRound(pValue As Double) As Double
Dim LWhole As Long
Dim LFraction As Double
'Retrieve integer part of the number
LWhole = Int(pValue)
'Retrieve the fraction part of the number
LFraction = pValue - LWhole
If LFraction < 0.25 Then
CustomRound = LWhole
Else
CustomRound = LWhole + 0.5
End If
End Function
Any help is highly appreciated. Thank you.
if the value behind the decimals is <.25 then it should round down to the whole number, if the value is >.25 but <.5 it should round up to .5, if the value is <.5 it should round up to the next whole number.
an example:
1.24 becomes 1
1.45 becomes 1.5
1.75 becomes 2
I've found this solution below, but need to add the rounding up part to the next whole number:
Function CustomRound(pValue As Double) As Double
Dim LWhole As Long
Dim LFraction As Double
'Retrieve integer part of the number
LWhole = Int(pValue)
'Retrieve the fraction part of the number
LFraction = pValue - LWhole
If LFraction < 0.25 Then
CustomRound = LWhole
Else
CustomRound = LWhole + 0.5
End If
End Function
Any help is highly appreciated. Thank you.