>>Can anybody help me to make this piece work?
>>The problem is that Math.Floor is type of Double and none of casting that I apply to the variables does not work so far. Getting
"Cannot implicitly convert type 'double' to 'int' " error all the time.
>>"
>>
>>C#, VS 2003
>>
>>{
>> int _CurrentPageIndex = 5;
>> int _PageButtonCount = 2;
>> int StartLoop = 0;
>>
>> StartLoop = (Math.Floor(_CurrentPageIndex / _PageButtonCount) * _PageButtonCount) + 1;
>>}
>>
>
>(1) There is a confusion in the compiler whether to convert (_CurrentPageIndex / _PageButtonCount) to double or to decimal, since floor can take both double and decimal
>You can help/hint the compiler by casting either _CurrentPageIndex or _PageButtonCount to a double or decimal
>
>(2) the result is an expression of type double or decimal. Assigning that to an int results in a loss of precision. The compiler does not do that for you. Hence you have to cast it to an int
>
StartLoop = (int)(Math.Floor((double)_CurrentPageIndex / _PageButtonCount) * _PageButtonCount) + 1;>
>But maybe this does what you're after also
>Since CurrentPageIndex and PageButtonCount are int, the result is an integer division with no remainder
>[ remember - this is not foxpro ]
>
>StartLoop = (_CurrentPageIndex / _PageButtonCount) * _PageButtonCount + 1;
>
Thanks Gregory and Viv!
this:
StartLoop = (int)(Math.Floor((double)_CurrentPageIndex / _PageButtonCount) * _PageButtonCount) + 1;
seems to work.
Amaizing, how many troubles you may have in .Net to do something very simple which does not present any problem in VFP. :)
Exactly like Rick Strahl used to say: ".Net makes hard things easy and easy things hard..." :-)
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro
"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison