Decimals for Rate - To Increase

Hi. Please advise how to increase decimal places for item rate and how to enable input Line total on purchase and sales invoice so then the rate is auto calculated by dividing amount with qty?