The round function is to take the decimal point. I have checked many methods that are not easy to use, so I have it.
round(cast(a/b as numeric), 2)
This can be used, you need to add a cast
Supplement: The mixture of to_char and round in postgresql
Everyone has used round in postgresql. How to display it when encountering decimals? See examples
SELECT to_char(round(127 * 0.1 / 67543,6)*10000,'90.99')
1.88
SELECT to_char(round(127 * 0.1 / 67543,6)*10000,'90.00')
1.88
SELECT to_char(round(150 * 0.1 / 50000,6)*1000,'90.09')
0.30
SELECT to_char(round(150 * 0.1 / 50000,6)*1000,'00.09')
00.30
SELECT to_char(round(150 * 0.1 / 50000,6)*1000,'99.09')
.30
Have you seen the rules?
Haha, the above results of SQL are explained: 0 is any placeholder. If there is data on 0 bits, the data will be displayed. If there is no data, the 0 is displayed. 9 is a real placeholder. If there is data on 9 bits (numbers greater than 0), the data will be displayed. If there is no data, nothing will be displayed.
So when we want to take percentage or thousandth fractions, and to satisfy the format, we must use 90.99 as the placeholder
The above is personal experience. I hope you can give you a reference and I hope you can support me more. If there are any mistakes or no complete considerations, I would like to give you advice.