So much fun. I was messing around with a fast VB conversion function. I just want to truncate double to integer.
value = Int(83.768) value == 83
Surprisingly, something in VB really worked.
Oh I forgot that this does not work with negative numbers
value = Int(-83.768) value == -84
... yes, it just happened. VB uses Banker rounding.
Public Function Trunc(ByVal value As Double) As Integer ' Truncate by calling Int on the Absolute value then multiply by the sign of the value. ' Int cannot truncate doubles that are negative Trunc = (Abs(value) / value) * Int(Abs(value)) End Function
If you want certain decimal places to do what Mac did only with abs around the value, so Int can truncate correctly.
Public Function Trunc2(ByVal value As Double, Optional ByVal num As Integer = 1) As Double ' Truncate by calling Int on the Absolute value then multiply by the sign of the value. ' Int cannot truncate doubles that are negative Dim sign As Integer sign = Abs(value) / value Trunc2 = sign * (Int(Abs(value) * (10 ^ num)) / (10 ^ num)) End Function
Hashplat
source share