In our Learning Management System someone in their infinite wisdom decided to keep non-standardized grades. As a result we have a table similar to this:
- Assignment 1 – 100
- Assignment 2 – 80
- Assignment 3 – 10/20
- Assignment 4 – 68
- Assignment 5 – 8/10
As you can see we have a mixture of percentages and fractions. What i’d like to do is check if the grade is a fraction i.e. 10/20 and if so convert it out to a percentage. Are there any built in php functions for either action? I was thinking of doing a strpos(‘/’/, $grade); to check if it was a fraction but is there a cleaner way? Additionally to break up the fraction and convert it to a decimal my initial thought was to explode the fraction grade on a / and do (array[1] * 100) / array[2].
Is there any better solution than the one i am thinking?
i believe that should work
dont have to deal with pesky regex either