rounding

  • Thread starter Thread starter Jean-Paul De Winter
  • Start date Start date
J

Jean-Paul De Winter

Hi,
Is there a way to round to ,5...
Exapmle:
7,4 should be 7.5
7.2 should be 7
6,8 should be 7
6,6 should be 6.5

Also,

Is there a way to prevent someone from entering numbers like 6,2 or 6.8.
I want them to enter numbers like:
6 or 6.5 or 7

Thanks
 
Jean-Paul De Winter formuleerde de vraag :
Hi,
Is there a way to round to ,5...
Exapmle:
7,4 should be 7.5
7.2 should be 7
6,8 should be 7
6,6 should be 6.5
You'll probably have to write a function for that but someone correct
me if I'm wrong
Also,

Is there a way to prevent someone from entering numbers like 6,2 or 6.8.
I want them to enter numbers like:
6 or 6.5 or 7
Look at the inputmask
 
1) You could write your own function to do this and call the function in the
control's AfterUpdate event to change the number. Use a rounding function or
input mask to limit the decimal to one decimal prior to calling this
function.

Public Function RoundToFive(sglNumber As Single) As Single
Dim intDecimal As Integer, intBase As Integer
intBase = Int(sglNumber)
intDecimal = sglNumber Mod intBase
Select Case intDecimal
Case 1, 2
RoundToFive = intBase
Case 3, 4, 6, 7
RoundToFive = intBase + 0.5
Case 8, 9
RoundToFive = intBase + 1
Case Else
RoundToFive = sglNumber
End Select
End Function

2) In the control's BeforeUpdate event, you could check the value of the
decimal and if it isn't 0 or 5, Cancel the update and pop-up a message for
the user.

Dim intDecimal As Integer
intDecimal = Me.ActiveControl Mod Int(Me.ActiveControl)
If intDecimal <> 5 And intDecimal <> 0 Then
Msgbox "Bad Number, try again. It should end in .5 or .0"
Cancel = True
End If
 
Back
Top