Short answer: Rent when you need a book for a short period and do not need to write in it; buy when you will use it for a long time.
How long do you need it
Short, one-time use favours renting where it is available; long-term study favours buying.
Will you write in it
If you will annotate heavily, buying is better.
Alternatives
Second hand is often a cost-effective middle path, and you can sell the book afterwards.
Related: renting or buying used.
Frequently asked questions
Is renting always cheaper?
Not always. Compare total cost with buying second hand and reselling.
Where can I buy second hand?
Browse second hand books on Bookaao.