In my Postgresql database, the Student
table has student_marks
and total_marks
columns.
I want to get the percentage based on student marks.
For example:
student_marks * 100 / total_marks => 118 * 100 / 147 = 80.27 = 80%
If the first two digits of decimal number are below 50, ex: 75.49 then it should be 75% or if the first two digits of decimal number are equal to 50 or above 50, ex: 67.50 or 67.52 then it should be 68% so
This query works for me:
select TO_CHAR(19.57, 'fm99%') as abc;
it returns 20%.
The problem is of the student get 100% marks:
select TO_CHAR(100, 'fm99%') as abc;
returns ##%
Please show me a solution for this or else suggest another way to do this.
Thank you.