Divide, 2/11....... after i get the answer 5.5 how would i get the 5 after the .?
Printable View
Divide, 2/11....... after i get the answer 5.5 how would i get the 5 after the .?
Code:'there must be a math function for this but I don't have
'msdn available and you are using VB3 so I don't even know
'if you have access to the InStr/cSng Functions.
Private Sub Form_Load()
'I assume there are better ways but this will work
'if using decimals you must be using single/double/long
'x = result of your division
Dim x As Single
x = 5.5
Dim SearchString, SearchChar, MyPos
'convert it to a string
SearchString = CStr(x)
'search for the .
SearchChar = "."
MyPos = InStr(1, SearchString, SearchChar, 1)
'if found MyPos will be > 0
If MyPos > 0 Then
'trim away all but what follows the .
SearchString = Right(SearchString, Len(SearchString) - MyPos)
'switch back to single
x = CSng(SearchString)
MsgBox x 'value of x as a single
End If
End Sub
Not sure if this works for everything, but you can try it out:
Code:Dim x As Single
x = (11 / 2 - 11 \ 2)
MsgBox (x)