everything seems simple, but for 15 minutes I can’t understand what is wrong and where I am on portage, why 3 and not 3.63 ...?

double w = owner.ClientSize.Width / prev_width;// 1680 /462 = 3 (3.63) 

Ps Sori for a stupid question, but I can not understand ..

  • understood thanks. - cyber_ua
  • just one number is enough to type to double. That is, either: (double)owner.ClientSize.Width / prev_width; or owner.ClientSize.Width / (double)prev_width; - Ivan Navoznov

2 answers 2

should be like this:

 double w = (double)1680/462; 

I will explain why. In your example, the script is

  1. If the integer 1680 divided by the integer 462 result is 3,636363 ... it turns out to be an integer (if it is not an integer, then the fractional part is discarded), that is, the result is 3 (of type int )
  2. The resulting result 3 (of type int ) is implicitly converted to type double .
  3. At the output we get the value of the variable w equal to 3.
  • sorry, but what is the value of your answer if absolutely the same thing was previously described in the comments? - DreamChild
  • one
    Well, actually, I wrote (or rather started writing) an answer, when there were no comments, when I posted an answer, I saw that there was a comment. What's the big deal? - Ivan Navoznov
  • @DreamChild, perhaps because the format of the site implies the answers in the "answers" and not in the comments? The comment cannot be marked with the "correct answer". Moreover, in this case, the reusability of the answer suffers when you come from a search engine to the interesting question, and the answer in the comments, it turns out. - pkuderov

Because divide the whole by the whole. And the answer will be whole. The easiest way is to read the first chapters of books and do something like this.

 double w = (double)owner.ClientSize.Width / (double)prev_width; 

or

 double w = owner.ClientSize.Width * 1.0 / prev_width;