I'm having trouble coming up with a function for this sort of weird math operation I'm trying to accomplish. Say you have two quantities of a liquid in ounces. The two quantities can be broken up into only four different parts: 1oz, 32nds of 1oz, 64ths of 1oz, and 128ths of 1oz. For example theses two quantities could be:
| OZ | 32 | 64 | 128 |
|---|---|---|---|
| 2 | 22 | - | 3 |
| 1 | 10 | - | 1 |
I need to calculate the difference between these two quantities. This is easy to do by hand, but not so much programmatically. The expected result for this situation would be 1oz, 12/32, 0/64 and 2/128. I must end up with the quantities broken up into their smallest proponents, so 32/32 should roll over to be 1oz, etc. What is the best way to implement this?
Here’s what I’ve been attempting most recently (just converting to and from decimal):
This math is based on https://www.calculatorsoup.com/calculators/time/decimal-to-time-calculator.php