Armin Zingler explained on 1/10/2011 :
> Am 11.01.2011 01:36, schrieb Tom Shelton:
>> After serious thinking Armin Zingler wrote :
>>> Am 10.01.2011 23:20, schrieb Tom Shelton:
>>>> Armin Zingler submitted this idea :
>>>>> Hi,
>>>>>
>>>>> is there a function in the Framework that cuts the places
>>>>> after the decimal point of a Double and converts to an Integer
>>>>> _without_ performing any rounding (as Convert.ToInt32 does)?
>>>>> I mean, what the IL code "conv.i4" does? ATM I'm using a function
>>>>> that exactly does what I need in a C++ helper library:
>>>>>
>>>>> static int ToInt32(double value)
>>>>> {
>>>>> return int(value);
>>>>> };
>>>>>
>>>>> But I want to get rid of it because a whole library for this
>>>>> function is oversized and because this simple function should be
>>>>> in the Framework, shouldn't it?
>>>>
>>>> Well... Math.Truncate? You would of course have to case the return to
>>>> an integer..
>>>
>>> Yes, but how to convert then?
>>
>> I don't understand?
>>
>> Module Module1
>>
>> Sub Main()
>> Dim d As Double = 7.9999999
>> Dim i As Integer = CInt(Math.Truncate(d))
>> Console.WriteLine(i)
>> End Sub
>>
>> End Module
>>
>> output = 7
>
> CInt perform rounding. That's what I want to avoid because it's unnecessary
> and costs time. It's unnecessary because Truncate has been called before.
I realize that, but there is no direct way that I know of in VB. If
you have option strict on, that is...
--
Tom Shelton
|