How to scale down an image by aspect ratio exactly?

I have an image that is (just for example, can be any size):

599 original width
599 original height

and a destination aspect ratio for example (can be any):

1:2

I want to scale down the image and make it exactly the aspect ratio, a simple multiplication gives only:

299.5 x 599

while I expect

299 x 598

How to get the expected result?

Sorry for my bad English, I find it hard for me to describe a mathematics question well.

You don't say what the class of problems you are working on, but one approach is to divide $599$ by $2$ and round down because you can't have fractional pixels. That gives the new dimension in that direction as $299$. Then multiply that by $2$ to get the size in the other direction, giving $598$. This gives the largest rectangle of proportion $1:2$ that fits in $599 \times 599$
• Your problem had a square aspect ratio to start. The aspect ratio you wanted had a $1$ in one proportion instead of something like $3:4$ I don't know the range of problems you want to work with, so can't make sure my solution is sufficient for the whole range. – Ross Millikan Mar 28 '18 at 5:25
• When you have aspect ratio $2:3$ it should work in one step. You should divide by the larger number and round down, so $599/3=199$. Your dimensions are then $2\cdot 199=398$ by $3 \cdot 199=597$ – Ross Millikan Mar 28 '18 at 13:53