T
Tequila
How can I truncate a number? 123456 truncate 12 result=3456
Thanks,
John
Thanks,
John
Tequila said:How can I truncate a number? 123456 truncate 12 result=3456
Thanks,
John
Dirk Goldgar said:If I understand you, that's really a text operation -- dropping the
leading two digits from the front of the string of decimal digits that
represent the value. So you'd convert it to a string from its internal
numeric representation, drop the digits, and convert the resulting
string back to a number. For example,
Dim lngNumber As Long
Dim strDigits As String
lngNumber = 123456
strDigits = CStr(lngNumber)
If Len(strDigits) > 2 Then
lngNumber = CLng(Mid(strDigits, 3))
Else
lngNumber = 0
End If
Douglas J. Steele said:Not wanting to seem argumentative, it could also be done using Mod.
To drop the first 2 digits of a 6 digit number, you could use:
Dim lngNumber As Long
lngNumber = 123456
lngNumber = lngNumber Mod 10000